前言
在进行数据爬取时,有时候遇到一些比较复杂的js逆向。在不考虑访问效率的情况下,使用selenium模拟浏览器的方法可以大大减少反反爬逆向工作量。但普通的selenium库是无法获取到类似set-cookie等参数的,这时候需要用到selenium-wire库。其用法类似selenium
一、安装
首先安装selenium-wire库
pip install selenium-wire
然后下载指定的chromedriver,根据电脑上的chrome版本进行下载
chromedriver下载地址
二、简易使用
from seleniumwire import webdriver
driver = webdriver.Chrome(executable_path='chromedriver.exe')
driver.get('https://www.baidu.com')
即可看到如下界面:
如果出现报错说chromedriver版本不匹配,并且提示了本地电脑上的chrome版本,则回到chromedriver下载地址下载相对应版本
三、加入参数
1. 隐藏浏览器窗口
如果要让浏览器窗口不显示而在后台允许,加入headless参数:
options = webdriver.ChromeOptions()
options.add_argument