0


Python+selenium模拟登录新方案

相信很多人在做爬虫过程中会遇到需要模拟登录的网站,这时候使用selenium模拟浏览器的方式就成了首选方案,但某些网站还会对selenium这种插件进行检测,一旦发现就会出现各种反爬机制(拒绝访问、验证码、加载不出来、人机判断等等)。今天就来介绍一种方案可以完美绕过这种检测的,就是使用Selenium 控制已经打开的浏览器。

1、找到本地安装的浏览器启动路径,例如Chrome

windows

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

mac

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

2、通过命令行启动ChromeDbug模式

windows

$ C:\Program Files (x86)\Google\Chrome\Application>chrome.exe --remote-debugging-port=9222

mac

$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -remote-debugging-port=9222

注:

  1. 启动浏览器dbug模式时需要把浏览器打开的进程先全部关闭。

  2. 9222是默认端口,可以随意修改。但别使用已经被占用的端口。

3、连接调试开关打开的chrome

options = webdriver.ChromeOptions()
options.debugger_address = "127.0.0.1:9222"
driver = webdriver.Chrome(options=options)

以上内容如果对你有所帮助,请点个赞,谢谢!


本文转载自: https://blog.csdn.net/weixin_42108731/article/details/125386964
版权归原作者 秋无之地 所有, 如有侵权,请联系我们删除。

“Python+selenium模拟登录新方案”的评论:

还没有评论