oilchem.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package services
  2. import (
  3. "context"
  4. "eta/eta_data_analysis/utils"
  5. "fmt"
  6. "log"
  7. "time"
  8. "github.com/chromedp/chromedp"
  9. )
  10. // 隆众咨询数据
  11. func OilchemLogin() {
  12. opts := append(
  13. chromedp.DefaultExecAllocatorOptions[:],
  14. chromedp.Flag("headless", false),
  15. )
  16. allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
  17. defer cancel()
  18. // 创建chrome实例
  19. ctx, cancel := chromedp.NewContext(
  20. allocCtx,
  21. chromedp.WithLogf(log.Printf),
  22. )
  23. defer cancel()
  24. var htmlContent string
  25. err := chromedp.Run(ctx,
  26. chromedp.Navigate(`https://chem.oilchem.net/chemical/methanol.shtml`),
  27. chromedp.Sleep(5*time.Second),
  28. chromedp.Click(`a[class="tpbtn left"]`, chromedp.ByQuery),
  29. chromedp.Sleep(2*time.Second),
  30. chromedp.SetValue(`input[name="username"]`, utils.OilchemAccount, chromedp.ByQuery),
  31. chromedp.SetValue(`input[name="password"]`, utils.OilchemPassword, chromedp.ByQuery),
  32. chromedp.Sleep(2*time.Second),
  33. chromedp.Click(`button[id="smsValid"]`, chromedp.ByQuery),
  34. chromedp.Sleep(5*time.Second),
  35. )
  36. time.Sleep(3 * time.Second)
  37. err = chromedp.Run(ctx,
  38. chromedp.Navigate(`https://www.oilchem.net/24-0801-09-4036018c523e4bbc.html`),
  39. chromedp.Sleep(2*time.Second),
  40. chromedp.OuterHTML("html", &htmlContent),
  41. )
  42. if err != nil {
  43. fmt.Println(err)
  44. }
  45. fmt.Println("htmlContent:" + htmlContent)
  46. utils.FileLog.Info("htmlContent:" + htmlContent)
  47. }
  48. func OilchemList(context.Context) (err error) {
  49. num := 2
  50. if utils.OilchemDataInit == "1" {
  51. num = 60
  52. }
  53. err = JiaChunList(num)
  54. if err != nil {
  55. utils.FileLog.Info("JiaChunList Err:", err)
  56. }
  57. err = NiaoSuList(num)
  58. if err != nil {
  59. utils.FileLog.Info("NiaoSuList Err:", err)
  60. }
  61. err = FuHeFeiList(num)
  62. if err != nil {
  63. utils.FileLog.Info("FuHeFeiList Err:", err)
  64. }
  65. err = ZhiJiangList(num)
  66. if err != nil {
  67. utils.FileLog.Info("ZhiJiangList Err:", err)
  68. }
  69. err = YuanYouList(num)
  70. if err != nil {
  71. utils.FileLog.Info("YuanYouList Err:", err)
  72. }
  73. return
  74. }