selenium -- 智能等待

selenium -- 智能等待,第1张

代码
# -*- coding: utf-8 -*-
# @Author   : zbz

url = "https://www.amazon.com/product-reviews/B091F3815B/ref=cm_cr_arp_d_viewopt_fmt?formatType=current_format"

from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

options = ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('lang=en-us')
options.add_argument("--headless")
browser = Chrome(options=options)
browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })
  """
})
browser.get(url)
try:
    element = WebDriverWait(browser, 3).until(
        lambda x: x.find_element(By.XPATH, '//div[@data-hook="cr-filter-info-review-rating-count"]')
    )
    print(element.text)
except Exception as e:
    print(type(e))
    print(e)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/716578.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存