selenium-free interface and implementation of anti-climb

selenium-free interface and implementation of anti-climb

No interface to perform

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

url="https://www.baidu.com"
chrome_options=Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")

chrome=webdriver.Chrome(executable_path="chromedriver",chrome_options=chrome_options)

chrome.get(url)
print(chrome.page_source)

chrome.quit()

To avoid the risk of selenium server discovery request

from selenium import webdriver
#实现无可视化界面
from selenium.webdriver.chrome.options import Options
#实现规避检测
from selenium.webdriver import ChromeOptions

url="https://www.baidu.com"

#无可视化
chrome_options=Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
#规避检测
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])

chrome=webdriver.Chrome(executable_path="chromedriver",chrome_options=chrome_options,options=option)

chrome.get(url)
print(chrome.page_source)

chrome.quit()

Guess you like

Origin www.cnblogs.com/zx125/p/11487665.html