12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package services
- import (
- "context"
- "eta/eta_data_analysis/utils"
- "fmt"
- "log"
- "time"
- "github.com/chromedp/chromedp"
- )
- // 隆众咨询数据
- func OilchemLogin() {
- opts := append(
- chromedp.DefaultExecAllocatorOptions[:],
- chromedp.Flag("headless", false),
- )
- allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
- defer cancel()
- // 创建chrome实例
- ctx, cancel := chromedp.NewContext(
- allocCtx,
- chromedp.WithLogf(log.Printf),
- )
- defer cancel()
- var htmlContent string
- err := chromedp.Run(ctx,
- chromedp.Navigate(`https://chem.oilchem.net/chemical/methanol.shtml`),
- chromedp.Sleep(5*time.Second),
- chromedp.Click(`a[class="tpbtn left"]`, chromedp.ByQuery),
- chromedp.Sleep(2*time.Second),
- chromedp.SetValue(`input[name="username"]`, utils.OilchemAccount, chromedp.ByQuery),
- chromedp.SetValue(`input[name="password"]`, utils.OilchemPassword, chromedp.ByQuery),
- chromedp.Sleep(2*time.Second),
- chromedp.Click(`button[id="smsValid"]`, chromedp.ByQuery),
- chromedp.Sleep(5*time.Second),
- )
- time.Sleep(3 * time.Second)
- err = chromedp.Run(ctx,
- chromedp.Navigate(`https://www.oilchem.net/24-0801-09-4036018c523e4bbc.html`),
- chromedp.Sleep(2*time.Second),
- chromedp.OuterHTML("html", &htmlContent),
- )
- if err != nil {
- fmt.Println(err)
- }
- fmt.Println("htmlContent:" + htmlContent)
- utils.FileLog.Info("htmlContent:" + htmlContent)
- }
- func OilchemList(context.Context) (err error) {
- num := 2
- if utils.OilchemDataInit == "1" {
- num = 60
- }
- err = JiaChunList(num)
- if err != nil {
- utils.FileLog.Info("JiaChunList Err:", err)
- }
- err = NiaoSuList(num)
- if err != nil {
- utils.FileLog.Info("NiaoSuList Err:", err)
- }
- err = FuHeFeiList(num)
- if err != nil {
- utils.FileLog.Info("FuHeFeiList Err:", err)
- }
- err = ZhiJiangList(num)
- if err != nil {
- utils.FileLog.Info("ZhiJiangList Err:", err)
- }
- err = YuanYouList(num)
- if err != nil {
- utils.FileLog.Info("YuanYouList Err:", err)
- }
- return
- }
|