selenium被识别,修改navigator的方法

# -*- coding:utf-8 -*-
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
# chrome_options.add_argument('user-agent=' + ua)
# chrome_options.add_argument("disable-infobars")
# chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })
  """
})

driver.get("http://www.macklin.cn/products/I861879")

time.sleep(10)
driver.close()
driver.quit()

你可能感兴趣的:(爬虫,selenium,chrome,爬虫)