|
@@ -6,7 +6,6 @@ import (
|
|
|
"eta/eta_data_analysis/models"
|
|
|
"eta/eta_data_analysis/utils"
|
|
|
"fmt"
|
|
|
- "github.com/chromedp/cdproto/cdp"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
"io"
|
|
|
"log"
|
|
@@ -21,11 +20,8 @@ import (
|
|
|
var (
|
|
|
downloadDir = utils.RZD_EXCEL_PATH
|
|
|
defaultDir = utils.RZD_DOWNLOAD_PATH
|
|
|
- rzdLoginPath = "https://clients.rystadenergy.com/clients/"
|
|
|
+ rzdLoginPath = "https://portal.rystadenergy.com/home"
|
|
|
rzdBatchSize = 500
|
|
|
-
|
|
|
- clientSearchLink = `div.d-none.d-lg-flex.flex-grow-1 a[href="/clients/search/"]`
|
|
|
- downloadButtonSelector = `div.btn.btn-link.btn-sm.dashboard-action.dashboard-action--download-data`
|
|
|
)
|
|
|
|
|
|
|
|
@@ -34,41 +30,32 @@ func downloadData(ctx context.Context) error {
|
|
|
if err := chromedp.Run(ctx,
|
|
|
chromedp.Sleep(5*time.Second),
|
|
|
chromedp.Navigate(rzdLoginPath),
|
|
|
- chromedp.WaitVisible(`div.d-none.d-lg-flex.flex-grow-1`, chromedp.ByQuery),
|
|
|
- chromedp.Click(clientSearchLink, chromedp.ByQuery),
|
|
|
- chromedp.WaitVisible(`input[class="ais-SearchBox-input rounded border py-2 px-3 shadow-sm font-size-14 w-100"]`, chromedp.ByQuery),
|
|
|
- chromedp.SetValue(`input[class="ais-SearchBox-input rounded border py-2 px-3 shadow-sm font-size-14 w-100"]`, "oil demand signals weekly report", chromedp.ByQuery),
|
|
|
- chromedp.Sleep(10*time.Second),
|
|
|
-
|
|
|
+ chromedp.WaitVisible(`a.mat-tooltip-trigger.analytics.home__link-card-icon[href="/analytics"]`, chromedp.ByQuery),
|
|
|
+ chromedp.Click(`a.mat-tooltip-trigger.analytics.home__link-card-icon[href="/analytics"]`, chromedp.ByQuery),
|
|
|
+ chromedp.Sleep(5*time.Second),
|
|
|
); err != nil {
|
|
|
return fmt.Errorf("下载 Analytics Library 数据错误: %v", err)
|
|
|
}
|
|
|
-
|
|
|
- xpath := `//div[@id='search-page-hits']//li//a[.//div//span[@class='align-middle' and text()='Data']]`
|
|
|
- var inputCount int
|
|
|
- var nodes []*cdp.Node
|
|
|
if err := chromedp.Run(ctx,
|
|
|
- chromedp.ActionFunc(func(ctx context.Context) error {
|
|
|
-
|
|
|
-
|
|
|
- if err := chromedp.Nodes(xpath, &nodes, chromedp.BySearch).Do(ctx); err != nil {
|
|
|
- return fmt.Errorf("检查节点失败: %v", err)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- inputCount = len(nodes)
|
|
|
- fmt.Printf("找到 %d 个匹配的元素\n", inputCount)
|
|
|
+ chromedp.WaitVisible(`#intro-home-page-step1`, chromedp.ByID),
|
|
|
+ chromedp.SetValue(`#intro-home-page-step1`, "oil demand signals weekly report", chromedp.ByID),
|
|
|
+ chromedp.SendKeys(`#intro-home-page-step1`, "\u000D", chromedp.ByID),
|
|
|
+ chromedp.Sleep(5*time.Second),
|
|
|
+ ); err != nil {
|
|
|
+ return fmt.Errorf("设置 input 标签值时发生错误: %v", err)
|
|
|
+ }
|
|
|
|
|
|
- if inputCount > 0 {
|
|
|
-
|
|
|
- return chromedp.MouseClickNode(nodes[0]).Do(ctx)
|
|
|
- }
|
|
|
- return nil
|
|
|
- }),
|
|
|
- chromedp.Sleep(10*time.Second),
|
|
|
+ if err := chromedp.Run(ctx,
|
|
|
+
|
|
|
+ chromedp.WaitVisible(`//div[contains(@class, 'download-btns')][1]//ul//li//button[contains(@class, 'mat-tooltip-trigger') and contains(@class, 'download__excel') and normalize-space(text())='Data']`, chromedp.BySearch),
|
|
|
+
|
|
|
+ chromedp.Click(`//div[contains(@class, 'download-btns')][1]//ul//li//button[contains(@class, 'mat-tooltip-trigger') and contains(@class, 'download__excel') and normalize-space(text())='Data']`, chromedp.BySearch),
|
|
|
+
|
|
|
+ chromedp.Sleep(5*time.Second),
|
|
|
); err != nil {
|
|
|
- return fmt.Errorf("下载 Analytics Library 数据错误: %v", err)
|
|
|
+ return fmt.Errorf("点击第一个下载按钮时发生错误: %v", err)
|
|
|
}
|
|
|
+
|
|
|
|
|
|
if err := waitAndRenameDownloadedFile("Oil_Demand_Signals_Weekly_Report_"+utils.GetCurrentYearMonth()+".xlsx", downloadDir); err != nil {
|
|
|
return err
|
|
@@ -150,6 +137,10 @@ func moveFile(source, destination string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func main() {
|
|
|
+ ResolverNet(context.Background())
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
func ResolverNet(cont context.Context) (err error) {
|
|
@@ -409,8 +400,8 @@ func login(ctx context.Context) error {
|
|
|
chromedp.Sleep(5*time.Second),
|
|
|
|
|
|
|
|
|
- chromedp.WaitVisible(`a[href="/clients/"]`, chromedp.ByQuery),
|
|
|
- chromedp.Sleep(5*time.Second),
|
|
|
+
|
|
|
+ chromedp.Sleep(5*time.Second), */
|
|
|
)
|
|
|
}
|
|
|
|