# -*- 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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)