亲测有效的python+selenium+chrome+webdriver模拟登录爬虫版本配置
爬虫要使用模拟登录那非selenium库莫属了,不过各个节点版本之间匹配问题有时候会让人疯掉,以下是安装血泪史后的亲测有效版本包括下载地址。
物理机:联想T480 win10 64位
python环境:anacondas+python3.8.3
selenium==4.0.0
pip install selenium==4.0.0
chrome 浏览器:版本 99.0.4844.51(正式版本) (64 位)
chrome历史版本 下载https://m.chromedownloads.net/chromenews/1081.html
chrome64位稳定版本下载https://www.chromedownloads.net/chrome64win-stable/
webdriver版本=chromedriver_win32.zip(webdriver 在windows只有32位,不过不影响64位的使用)
webdriver下载地址:http://chromedriver.storage.googleapis.com/index.html
另外建议拷贝chromedriver.exe放在谷歌浏览器安装目录下和python安装目录下各放一份,避免出现找不到webdriver报错,另外也就不需要指定路径了。直接调用
-------------
附上一份调用参数
全部的参数解释地址:https://peter.sh/experiments/chromium-command-line-switches/
部分常用参数如下:
chrome_options.add_argument('--headless') # 浏览器不提供可视化页面
chrome_options.add_argument('--disable-gpu') # 禁用GPU加速
chrome_options.add_argument('--disable-infobars') # 禁用浏览器正在被自动化程序控制的提示
chrome_options.add_argument('--user-agent=""') # 设置请求头的User-Agent
chrome_options.add_argument('--window-size=1280x1024') # 设置浏览器分辨率(窗口大小)
chrome_options.add_argument('--start-maximized') # 最大化运行(全屏窗口),不设置,取元素会报错
chrome_options.add_argument('--incognito') # 隐身模式(无痕模式)
chrome_options.add_argument('--hide-scrollbars') # 隐藏滚动条, 应对一些特殊页面
chrome_options.add_argument('--disable-javascript') # 禁用javascript
chrome_options.add_argument('--blink-settings=imagesEnabled=false') # 不加载图片, 提升速度
chrome_options.add_argument('--ignore-certificate-errors') # 禁用扩展插件并实现窗口最大化
chrome_options.add_argument('--disable-software-rasterizer') # 禁用 3D 软件光栅化器
chrome_options.add_argument('--disable-extensions') # 禁用扩展
chrome_options.add_argument('--start-maximized') # 启动浏览器最大化