代码之家  ›  专栏  ›  技术社区  ›  Flissi Hamed

从抓取aliexpress到使用chromedp的无头浏览器

  •  0
  • Flissi Hamed  · 技术社区  · 4 月前

    当我使用此代码导航根链接时”https://www.aliexpress.com/?language=en&region=US”使用chromedp。Aliexpress将我重定向到阿拉伯语页面。

    我需要直接进入英文页面

    这是我正在使用的代码:

    err := chromedp.Run(ctx,
        chromedp.EmulateViewport(1920, 1980),
        // Navigate to AliExpress with English language and US region
        chromedp.Navigate(`https://www.aliexpress.com/?language=en&region=US`),
        chromedp.WaitVisible(`body`, chromedp.ByQuery),
        chromedp.Sleep(5*time.Second), // Wait for the page to fully load
        // Extract all links with their text and href
        chromedp.Evaluate(`
            JSON.stringify(
                Array.from(document.querySelectorAll('a')).map(a => ({
                    text: a.textContent.trim(),
                    href: a.href
                }))
            )
        `, &links),
    )
    if err != nil {
        log.Fatal(err)
    }
    
    

    如果需要先添加一些标题,请帮助我

    0 回复  |  直到 4 月前
    推荐文章