Selenium+python3

2020-04-24 10:13:28 浏览数 (1)

18.

from selenium import webdriver from selenium.webdriver import ChromeOptions

option = ChromeOptions() option.add_experimental_option('excludeSwitches', ['enable-automation']) option.add_experimental_option('useAutomationExtension', False) browser = webdriver.Chrome(options=option) browser.execute_script('Object.defineProperty(navigator, "webdriver", {get: () => undefined})') browser.get('https://antispider1.scrape.cuiqingcai.com/')

19.

from selenium import webdriver from selenium.webdriver import ChromeOptions

option = ChromeOptions() option.add_experimental_option('excludeSwitches', ['enable-automation']) option.add_experimental_option('useAutomationExtension', False) browser = webdriver.Chrome(options=option) browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', { 'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})' }) browser.get('https://antispider1.scrape.cuiqingcai.com/')

20.绕过检测

option = ChromeOptions() option.add_experimental_option('excludeSwitches', ['enable-automation']) option.add_experimental_option('useAutomationExtension', False) browser = webdriver.Chrome(options=option) browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', { 'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})' }) browser.get('https://antispider1.scrape.cuiqingcai.com/')

21.设置无头

from selenium import webdriver from selenium.webdriver import ChromeOptions

option = ChromeOptions() option.add_argument('--headless') browser = webdriver.Chrome(options=option) browser.set_window_size(1366, 768) browser.get('https://www.baidu.com') browser.get_screenshot_as_file('preview.png')

0 人点赞