python——selenium框架实现无头浏览器访问 + 规避检测配置
生活随笔
收集整理的這篇文章主要介紹了
python——selenium框架实现无头浏览器访问 + 规避检测配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
備注:
有的時候,我們希望,selenium訪問的時候,不要出現瀏覽器,
那么就需要進行配置。具體配置看代碼。
運行代碼
# !/user/bin/env python # -*- coding: utf-8 -*- # 谷歌瀏覽器 - 無頭界面 from selenium import webdriver from time import sleep# 實現無可視化界面 from selenium.webdriver.chrome.options import Options# 實現規避檢測 from selenium.webdriver import ChromeOptionsoptions = Options() options.add_argument('--headless') options.add_argument('--disable-gpu')# 實現規避檢測 chromeOptions = ChromeOptions() chromeOptions.add_experimental_option('excludeSwitches', ['enable-automation'])if __name__ == '__main__':browser = webdriver.Chrome(executable_path='./chromedriver.exe', chrome_options=options, options=chromeOptions)# 無可視化界面(無頭瀏覽器) phantomJsbrowser.get('https://www.baidu.com')print(browser.page_source)sleep(2)browser.quit()總結
以上是生活随笔為你收集整理的python——selenium框架实现无头浏览器访问 + 规避检测配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue-router常见问题解决方案。(
- 下一篇: 基于selenium实现12306的登录