Reptile headless browser evade monitoring

Headless browser

- phantomJs: browser no visual interface
- Google headless browser:
from selenium.webdriver.chrome.options Import Options.
= the Options chrome_options ()
chrome_options.add_argument ( '- headless')
chrome_options.add_argument ( '- disable-GPU')
Browser = webdriver.Chrome (= executable_path path, chrome_options = chrome_options)

# 无头浏览器举例
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

bro = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=chrome_options)

bro.get('https://www.baidu.com')
sleep(3)
print(bro.page_source)
bro.save_screenshot('1.png')

bro.quit()

Evade monitoring

Many large sites have now adopted a monitoring mechanism for selenium. For example, under normal circumstances we window.navigator.webdriver visit sites such as Taobao is a browser 
undefined. Selenium is used to access the value is true. So how to solve this problem? 

Only you need to set the startup parameters Chromedriver to solve the problem. Before starting Chromedriver, Open as Chrome Experiment parameters excludeSwitches, its value [ ' enable-Automation ' ], complete code as follows: 

from selenium.webdriver Import Chrome
 from selenium.webdriver Import ChromeOptions 

Option = ChromeOptions () 
option.add_experimental_option ( ' excludeSwitches ' , [ ' enable-Automation ' ]) 
Driver = the Chrome (Options = Option)

 

- related sites will be monitored selenium initiated request - website background can be monitored according to the return value of selenium window.navigator.webdriver
-: undefinded selenium request is not made to send
a request selenium initiated: - true
method to circumvent the monitoring of - :
from selenium.webdriver Import ChromeOptions
Option = ChromeOptions ()
option.add_experimental_option ( 'excludeSwitches', [ 'Automation-enable'])
Bro = webdriver.Chrome (executable_path = 'chromedriver.exe', Options = Option)

from selenium import webdriver
from selenium.webdriver import ChromeOptions
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
#实现了规避监测
bro = webdriver.Chrome(executable_path='chromedriver.exe',options=option)
bro.get('https://www.taobao.com/')

 

Guess you like

Origin www.cnblogs.com/XLHIT/p/11317107.html