关注分享主机优惠活动
国内外VPS云服务器

Python+selenium-12306解决实战中的登录滑块问题(Python滑动验证码处理)

解决实战中登录滑块的问题。如何在登录过程中使用开发者模式参考?请参考本文尝试自动测试或初级爬虫登录模块和滑块验证。

Python+selenium-12306解决实战中登录滑块的问题。上一节12306登录过程中如何使用开发者模式参考所遇到问题的解决方案。

你可以参考这篇文章来尝试自动测试或者主爬虫(登录模块)和滑块验证。使用网站:Chrome(第39版)

滑块验证遇到的问题:帐户密码输入后,将由滑块验证。即使拖动成功,也会使刷新再次尝试。就算再拖,问题也在chromedriver。该网站将检测到它是一个自动测试工具,并阻止您登录。

解决方法是使用较低版本的chrome和相应的chromedriver。具体版本可以在相应的csdn上找到(文末也有评论和chromedriver各版本下载地址),可以解决12306的滑块问题,但是有一个问题。该版本不支持购买服务,只能作为练习使用。对于其他网站,比如淘客,我去年尝试攻克了同样的问题,今年找到了解决方案,适用性很强。可以试试,注意用chrome和chromedriver的较低版本(39可以)找$ CDC _ lasutophvczlmcfl,文章链接。

我用的chrome是39版。下载地址:http://www.121down.com/soft/softview-103980.html # down address①记得设置自动更新禁止:https://blog.csdn.net/weixin_41990913/article/details/. 90912790②还有就是环境变量的配置。因为旧版chrome不一定安装在c盘上,所以要根据具体位置添加到用户变量PATH中,chromedriver.exe和chrome.exe放在同一个文件夹中。

12306登录流程注意事项比较详细,不做过多解释。

from selenium导入web driver from selenium . web driver . common . action _ chains导入ActionChainsfrom time导入sleep # ----------------------------------------4。--------#只有使用chrome39版本,才能避免selenium检测选项= webdriver.chromeoptions () #开发者模式的切换,并进行设置。打开浏览器不会被识别为自动化测试工具选项. add _ experimental _ option(" exclude switches ",[" enable -automation "])option . binary _ location = " d://Google Chrome 32位v 39 . 0 . 2171 . 99//app//Google Chrome//Chrome . exe " # Own directory Chrome location driver = web driver . Chrome(Chrome _ options = option,Executable _ path = " d://Google Chrome 32位v 39 . 0 . 2171 . 99//app//Google Chrome Chrome Chrome--------driver . maximize _ window()driver . implicitly _ wait(10)URL = " https://kyfw . 12306 . cn/OTN/left ticket/init " driver . get(URL)# ------------------------------动作链(驱动程序)。移动偏移量(1000,560)。单击()。用鼠标左键执行()# Click,其中1000是X坐标,500是Y坐标。可以得到坐标driver . find _ element _ by _ id(" log in _ user ")。click()driver . find _ element _ by _ XPath("//ul[@ class = " log in -HD "]/Li[2]/a ")。单击()#。进步司机。按id查找元素(“J-用户名”)。send _ keys(" ")驱动程序。find _ element _ by _ id(“J-密码”)。send _ keys(" " #添加您的帐户密码driver . find _ element _ by _ XPath("/div[@ class = " log in -BTN "]/a ")。点击()#登录睡眠(2)# -----------------------------------4。+-----#拖动滑块dragger = driver。Find _ element _ by _ ID ("NC _ 1 _ n1z ")动作=动作链(驱动程序)动作。点击并按住(拖动)。执行()#单击并拖动滑块动作。drag _ and _ drop _ by _ offset(dragger,300,0)。执行()#并拖动长距离滑块。在开发者模式下,你可以看到sleep (2)驱动。find _ element _ by _ XPath("//div[@ class = " modal -ft "]/a ")。单击()#单击以指示如何使用开发人员模式。先按F12快速找到按钮对应的html代码位置:点击开发工具左上角。如图点击你想找的按钮,比如登录,右边的开发工具会自动显示对应的html代码引用某宝:https://blog.csdn.net/taojian_/article/details/97758632?. Spm = 1001 . 2014 . 3001 . 5501版本对应:https://blog.csdn.net/Yunwubanjian/article/details/86539432 chrome driver:http://chromedriver.storage.googleapis.com/. Index.html 12306实战:http://www.uml.org.cn/Test/201808024.asp

未经允许不得转载:主机频道 » Python+selenium-12306解决实战中的登录滑块问题(Python滑动验证码处理)

评论 抢沙发

评论前必须登录!