以下设置基于 selenium==3.6.0
谷歌浏览器设置
通用部分
1 | from selenium import webdriver |
常用设置
1 | # 谷歌无头模式 |
Chrome可设置的参数列表List of Chromium Command Line Switches
禁止图片加载
1 | prefs = {"profile.managed_default_content_settings.images": 2} |
代理ip设置
1 | # 静态IP |
cookie设置
1 | # 删除所有的cookie |
火狐浏览器设置
通用部分
1 | from selenium import webdriver |
常用设置
1 | firefox_options.add_argument('--headless') |
代理ip设置
1 |
|
userAgent设置
1 | profile = webdriver.FirefoxProfile() |
PhantomJS设置
参考链接github
通用部分
1 | from selenium import webdriver |
常用设置
1 | # 设置userAgent |
headers和代理ip设置
1 | headers = { |
代理ip设置
方式一:
1 | service_args = [ |
方式二:
1 | proxy = Proxy({ |
userAgent设置
方式一:
1 | webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.userAgent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36' |
方式二:
1 | dcap = DesiredCapabilities.PHANTOMJS.copy() |
禁用图片设置
1 | dcap = DesiredCapabilities.PHANTOMJS.copy() |
PhantomJS 代理ip动态切换
1 | from selenium import webdriver |
结合scrapy使用
1 | from selenium import webdriver |
常用useragent
chrome
1 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1", |
Safari
1 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10", |
Firefox
1 | "Mozilla/5.0 (Macintosh; U; Mac OS X Mach-O; en-US; rv:2.0a) Gecko/20040614 Firefox/3.0.0 ", |
以上内容参考文章: