代码拉取完成,页面将自动刷新
from selenium import webdriver
from selenium.webdriver.chrome import options
# 无可视化的相关设置模块
from selenium.webdriver.chrome.options import Options
# 实现规避检测
from selenium.webdriver import ChromeOptions
from time import sleep
# 实现无可视化的相关设置
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# 实现检测的规避
option=ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])
bro = webdriver.Chrome(
executable_path='./python-test/chromedriver', chrome_options=chrome_options,options=option)
# 无可视化 即 无头浏览器
bro.get('https://www.baidu.com')
# 获取网页源码 page_source属性
print(bro.page_source)
sleep(2)
bro.quit()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。