美文网首页
python+selenium反爬策略

python+selenium反爬策略

作者: Sirius之剣 | 来源:发表于2020-05-22 08:11 被阅读0次
    from selenium import webdriver
    
    path = "\\\\chromedriver.exe"
    
    driver = webdriver.Chrome(executable_path=path)
    option = webdriver.ChromeOptions()
    option.binary_location=r'\\\\\chrome.exe'
    driver = webdriver.Chrome(executable_path=path,options=option)
    driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
      "source": """
        Object.defineProperty(navigator, 'webdriver', {
          get: () => undefined
        })
      """
    })
    
    
    
    driver.get("https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html")
    
    

    https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html
    可以判断有没有暴露webdriver

    由于selenium 版本更新
    新的方法为
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service

    尝试传参

    s = Service("chromedriver.exe")
    driver = webdriver.Chrome(service=s)

    driver.get('https://www.baidu.com/')
    driver.quit()

    相关文章

      网友评论

          本文标题:python+selenium反爬策略

          本文链接:https://www.haomeiwen.com/subject/atufahtx.html