找回密码
 会员注册
查看: 29|回复: 0

python通过selenium实现自动登录及轻松过滑块验证、点选验证码(2024-06-14)

[复制链接]

2万

主题

0

回帖

7万

积分

超级版主

积分
71625
发表于 2024-9-10 00:32:49 | 显示全部楼层 |阅读模式
一、chromedriver配置环境搭建请确保下载的驱动程序与你的Chrome浏览器版本匹配,以确保正常运行。1、Chrome版本号chrome的地址栏输入chrome://version,自然就得到125.0.6422.142版本125.0.6422.142(正式版本)(64位)(图1Chrome版本号)2、最新chromedriver版本下载地址https://googlechromelabs.github.io/chrome-for-testing/(图2最新chromedriver版本下载地址)3、查看chromedriver版本号chromedriver--version(图3查看chromedriver版本号)4、chromedriver.exe放置位置与python.exe同目录(图4chromedriver.exe放置位置)5、安装seleniumpipinstallselenium(出现下图是已经成功安装4.10.0版本了)6、查看selenium版本号pipshowselenium就可以查看版本号了(Version=4.10.0)(图5查看selenium版本号)7、卸载seleniumpipuninstallselenium8、指定selenium安装版本输入pipinstallselenium==3.3.1(指定安装3.3.1版本)二、selenium自动登录Selenium添加Cookie来实现自动登录。总的来说分两步1、第一步获取你登录的cookie,以csdn为例driver=webdriver.Chrome()driver.get('https://www.csdn.net/')start=time()sleep(15)//这里设置的是等待多少秒,也就是浏览器等待你登录,在这之后就去检查cookie,。try:  driver.refresh()//先刷新界面  print(driver.get_cookies())//获得cookie并打印exceptExceptionase:  print(e)  print(f'耗时:{time()-start}')然后在控制台你就可以得到一个字典格式的cookies2、第二步就是把第一步中得到的cookie放到webdriver里driver=webdriver.Chrome()driver.get('https://www.csdn.net/')driver.delete_all_cookies()//先清除原有的cookies=//这里把第一步的cookie复制上就行forcookieincookies:  driver.add_cookie(cookie)driver.refresh()//带着cookie重新加载3、webdriver中常用的cookie方法webdriver中提供了操作cookie的相关方法:get_cookies()          获得cookie信息add_cookie(cookie_dict)    添加cookiedelete_cookie(name)      删除特定(部分)的cookiedelete_all_cookies()       删除所有的cookie4、自动登录完整源码url="https://mygiftcard.jd.com/giftcard/myGiftCardInit.action"deflogin(driver):driver.get('https://www.jd.com/')driver.switch_to.window(driver.window_handles[-1])driver.maximize_window()driver.delete_all_cookies()cookies=[{'domain':'.jd.com','expiry':1717384813,'httpOnly':False,'name':'__jdb','path':'/','sameSite':'Lax','secure':False,'value':'76161171.5.1717382950957103922947|1.1717382951'},{'domain':'.jd.com','expiry':1732935013,'httpOnly':False,'name':'__jda','path':'/','sameSite':'Lax','secure':False,'value':'76161171.1717382950957103922947.1717382951.1717382951.1717382951.1'},{'domain':'.jd.com','httpOnly':False,'name':'__jdc','path':'/','sameSite':'Lax','secure':False,'value':'76161171'},{'domain':'.jd.com','expiry':1748918985,'httpOnly':False,'name':'pinId','path':'/','sameSite':'None','secure':True,'value':'YCe8rw2G6w2zBk65PfDfDg'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':False,'name':'pin','path':'/','sameSite':'None','secure':True,'value':'jd_XLCuliLsIoml'},{'domain':'.jd.com','expiry':1717386601,'httpOnly':False,'name':'jsavif','path':'/','sameSite':'Lax','secure':False,'value':'1'},{'domain':'.jd.com','expiry':1717384801,'httpOnly':False,'name':'token','path':'/','sameSite':'Lax','secure':False,'value':'58b2853fe33d43b6606c5a21df75d6e5,3,954101'},{'domain':'.jd.com','expiry':1719975003,'httpOnly':False,'name':'ipLoc-djd','path':'/','sameSite':'Lax','secure':False,'value':'25-2258-2261-6568'},{'domain':'www.jd.com','expiry':1717386590,'httpOnly':False,'name':'UseCorpPin','path':'/','sameSite':'Lax','secure':False,'value':'jd_XLCuliLsIoml'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':False,'name':'_tp','path':'/','sameSite':'None','secure':True,'value':'gcPCiSoOxTEQh1UmLWSJmA%3D%3D'},{'domain':'.jd.com','expiry':1718246952,'httpOnly':False,'name':'areaId','path':'/','sameSite':'Lax','secure':False,'value':'25'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':False,'name':'unick','path':'/','sameSite':'None','secure':True,'value':'717tjgq12eb3u3'},{'domain':'.jd.com','expiry':1717383072,'httpOnly':False,'name':'_gia_d','path':'/','sameSite':'Lax','secure':False,'value':'1'},{'domain':'.jd.com','expiry':1751942985,'httpOnly':False,'name':'TrackID','path':'/','sameSite':'None','secure':True,'value':'16Qvq9anbTkSX8gr4zaukUq5uQYslojZC9OQmewQghRGZ3XvjG_MMnzr_vyEIKSdUCtJ2wRpSFTY3eQtR-mtgEtTLaduuEqMy1V9rbOxT2sDX0aNazsKZ9ymfF8kbb66r'},{'domain':'.jd.com','expiry':1751943003,'httpOnly':False,'name':'shshshfpb','path':'/','sameSite':'Lax','secure':False,'value':'BApXcwpUJ3-pAgpgn7ERHMlecUhcGxJTHBlV5Lnto9xJ1MukUQIC2'},{'domain':'.jd.com','expiry':1751943002,'httpOnly':False,'name':'shshshfpa','path':'/','sameSite':'Lax','secure':False,'value':'52743637-1e03-a986-e555-3b60bd02251d-1717382954'},{'domain':'.jd.com','expiry':1751942954,'httpOnly':False,'name':'shshshfpx','path':'/','sameSite':'Lax','secure':False,'value':'52743637-1e03-a986-e555-3b60bd02251d-1717382954'},{'domain':'www.jd.com','expiry':1748918953,'httpOnly':False,'name':'o2State','path':'/','sameSite':'Lax','secure':False,'value':'{%22webp%22:true%2C%22avif%22:true%2C%22lastvisit%22:1717382953020}'},{'domain':'.jd.com','expiry':1718678985,'httpOnly':True,'name':'thor','path':'/','sameSite':'None','secure':True,'value':'B4C20964EEB81D93A1282B10D740DDCE93E6BF376C1A027834CA7420581040CA1F1691CE77DF8E8D4839BB18578D59CADD7B65F3464D14E69D56C466193409E2C5CC1CCC0FB0077D600F5E5A9050977080A6CD9DB54BF53D86A4A33D85C531B9CBA745CE208771BE1D5DFCEBADFD8E0CEB8C892454D65E7595BB979BE56296A5F7B62DAF0FD0D84D7FE1241F16E5B46A7A60AB7C12103EA76433421EA1F54E0A'},{'domain':'.jd.com','expiry':1743302958,'httpOnly':False,'name':'3AB9D23F7A4B3C9B','path':'/','sameSite':'Lax','secure':False,'value':'IGRRJT2FGAUX2L3XBSLXZRHOWGH7YNRHMBQHXA7OMUM75D6BQNTIV6YWQQLNKHV2URUHMEDS7BVALS47ABD56MW5TA'},{'domain':'.jd.com','expiry':1718679002,'httpOnly':True,'name':'flash','path':'/','sameSite':'None','secure':True,'value':'2_zpZqs4H7M7_a9OhxVV4eMXgMPNf1o8Lxl-gS2Cneh79n2xY8IA6o9y5JglFeAKaQiZht9zwAUXVJco4lj9A4vcdvIQiBDvy8LbsO_AFm1vttvRjlsuRLrbjHGIQSlouU9NJknNKUB8TbCWUlqFfY8wD2CdBj94DPObXyoggI_DK*'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':True,'name':'_pst','path':'/','sameSite':'None','secure':True,'value':'jd_XLCuliLsIoml'},{'domain':'.jd.com','expiry':1717384801,'httpOnly':False,'name':'__tk','path':'/','sameSite':'Lax','secure':False,'value':'VnTIiUTISDSEikqDVAvHVAvJTLe5Wne3iLTHiUSFikuATcVIVkq3i2,3,954101'},{'domain':'.jd.com','expiry':1748486952,'httpOnly':False,'name':'3AB9D23F7A4B3CSS','path':'/','sameSite':'Lax','secure':False,'value':'jdd03IGRRJT2FGAUX2L3XBSLXZRHOWGH7YNRHMBQHXA7OMUM75D6BQNTIV6YWQQLNKHV2URUHMEDS7BVALS47ABD56MW5TAAAAAMP3QADWNQAAAAACGG4IYVAGJI3JMX'},{'domain':'.jd.com','expiry':1732935018,'httpOnly':False,'name':'__jdu','path':'/','sameSite':'Lax','secure':False,'value':'1717382950957103922947'},{'domain':'.jd.com','httpOnly':False,'name':'ceshi3.com','path':'/','sameSite':'None','secure':True,'value':'000'},{'domain':'.jd.com','expiry':1718678950,'httpOnly':False,'name':'__jdv','path':'/','sameSite':'Lax','secure':False,'value':'76161171|direct|-|none|-|1717382950958'}]forcookieincookies:driver.add_cookie(cookie)##driver.refresh()driver.get(url)'运行运行三、selenium自动填写表单分为两步:一是取得元素(文本框、按钮等),二是执行输入、点击等操作。1、第一步、获取元素在Chrome里,鼠标停留在文本框,使用“检查元素”功能,在下方的调试窗口,右键“复制->复制完整XPath”(如下图),得到“文本框”对应的XPath,使用Selenium提供的send_keys命令实现文本输入。(图6Crome里取得元素XPath)2、第二步、执行输入、点击等操作执行输入driver.find_element(By.XPATH,'/html/body/div[4]/div/div/div[2]/div/div[1]/div/div/div/div/div[2]/div[2]/div[2]/input').send_keys(card_id)执行点击driver.find_element(By.XPATH,'/html/body/div[4]/div/div/div[2]/div/div[1]/div/div/div/div/div[2]/div[2]/div[3]/div').click()3、获取元素属性    ele_big=driver.find_element(By.ID,"cpc_img")    ele_small=driver.find_element(By.ID,"small_img")    src_big=ele_big.get_attribute('src')    src_small=ele_small.get_attribute('src')四、pyautogui自动化控制鼠标和键盘操作PyAutoGUI是一个纯Python的GUI自动化工具,其目的是可以用程序自动控制鼠标和键盘操作,多平台支持(Windows,OSX,Linux)。1、安装pip3installpyautogui2、pyautogui鼠标操作样例importpyautogui#获取当前屏幕分辨率screenWidth,screenHeight=pyautogui.size()#获取当前鼠标位置currentMouseX,currentMouseY=pyautogui.position()#2秒钟鼠标移动坐标为100,100位置绝对移动#pyautogui.moveTo(100,100,2)pyautogui.moveTo(x=100,y=100,duration=2,tween=pyautogui.linear)#鼠标移到屏幕中央。pyautogui.moveTo(screenWidth/2,screenHeight/2)#鼠标左击一次#pyautogui.click()#x#y#clicks点击次数#interval点击之间的间隔#button'left','middle','right'对应鼠标左中右或者取值(1,2,or3)#tween渐变函数#pyautogui.click(x=None,y=None,clicks=1,interval=0.0,button='left',duration=0.0,tween=pyautogui.linear)#鼠标相对移动,向下移动#pyautogui.moveRel(None,10)pyautogui.moveRel(xOffset=None,yOffset=10,duration=0.0,tween=pyautogui.linear)#鼠标当前位置0间隔双击#pyautogui.doubleClick()pyautogui.doubleClick(x=None,y=None,interval=0.0,button='left',duration=0.0,tween=pyautogui.linear)#鼠标当前位置3击#pyautogui.tripleClick()pyautogui.tripleClick(x=None,y=None,interval=0.0,button='left',duration=0.0,tween=pyautogui.linear)#右击pyautogui.rightClick()#中击pyautogui.middleClick()#用缓动/渐变函数让鼠标2秒后移动到(500,500)位置#usetweening/easingfunctiontomovemouseover2seconds.pyautogui.moveTo(x=500,y=500,duration=2,tween=pyautogui.easeInOutQuad)#鼠标拖拽pyautogui.dragTo(x=427,y=535,duration=3,button='left')#鼠标相对拖拽pyautogui.dragRel(xOffset=100,yOffset=100,duration=,button='left',mouseDownUp=False)#鼠标移动到x=1796,y=778位置按下pyautogui.mouseDown(x=1796,y=778,button='left')#鼠标移动到x=2745,y=778位置松开(与mouseDown组合使用选中)pyautogui.mouseUp(x=2745,y=778,button='left',duration=5)#鼠标当前位置滚轮滚动pyautogui.scroll()#鼠标水平滚动(Linux)pyautogui.hscroll()#鼠标左右滚动(Linux)pyautogui.vscroll()移动滑块函数defmy_slide(pos,distance):start_x=pos[0]start_y=pos[1]end_x=pos[0]+distanceend_y=pos[1]#移动鼠标到起始位置pyautogui.moveTo(start_x,start_y,duration=0.3)#按下鼠标左键pyautogui.mouseDown()#往右多拖到20xppyautogui.moveTo(end_x-20,end_y-20,duration=0.4)#拖回结束位置pyautogui.moveTo(end_x,end_y,duration=0.5)#松开鼠标左键pyautogui.mouseUp()'运行运行3、pyautogui键盘操作样例#模拟输入信息pyautogui.typewrite(message='Helloworld!',interval=0.5)#点击ESCpyautogui.press('esc')#按住shift键pyautogui.keyDown('shift')#放开shift键pyautogui.keyUp('shift')#模拟组合热键pyautogui.hotkey('ctrl','c')五、python屏幕截图我们需要用到Python的pillow模块中的ImageGrab类的grab()方法即可实现,具体代码如下:img=ImageGrab.grab(bbox=(x,y,width,height))img=ImageGrab.grab(bbox=(759,421,1141,793))img.save('./sel.jpg')该方法中bbox参数中传入需要截取图片的区域即可。其中x、y表示截取图片的左上角位置坐标,width、height参数中传入截取图片的宽度和高度。如果是全屏幕截取,则x,y=0,0;width、height传入屏幕分辨率中的宽度和高度即可。六、python通过selenium自动登录及轻松过滑块验证、点选验证码源代码fromseleniumimportwebdriverfromselenium.webdriver.chrome.serviceimportServicefromselenium.webdriver.chrome.optionsimportOptionsimportpyautoguiimporttimeimportwebbrowser,base64,iofromPILimportImageimportrandomimportcv2importpyautoguiimporttimeimportwebbrowserimportrequests,json,reimporttimeimportrandomimportshutilimportpyperclipfromselenium.webdriver.support.uiimportWebDriverWaitfromselenium.webdriver.supportimportexpected_conditionsasECfromselenium.webdriver.common.byimportByfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.action_chainsimportActionChainsimportkeyboard,os,uuidfromPILimportImageGrabfromYdmVerifyimportYdmVerifyy=YdmVerify()##author:byc6352##technicalsupport:byc6352ormetabycfor39848872card_id='55ADCB28DBC56EB4'url="https://mygiftcard.jd.com/giftcard/myGiftCardInit.action"deflogin(driver,cookies=''):##自动登录driver.get('https://www.jd.com/')driver.switch_to.window(driver.window_handles[-1])driver.maximize_window()driver.delete_all_cookies()ifcookies=='':cookies=[{'domain':'.jd.com','expiry':1717384813,'httpOnly':False,'name':'__jdb','path':'/','sameSite':'Lax','secure':False,'value':'76161171.5.1717382950957103922947|1.1717382951'},{'domain':'.jd.com','expiry':1732935013,'httpOnly':False,'name':'__jda','path':'/','sameSite':'Lax','secure':False,'value':'76161171.1717382950957103922947.1717382951.1717382951.1717382951.1'},{'domain':'.jd.com','httpOnly':False,'name':'__jdc','path':'/','sameSite':'Lax','secure':False,'value':'76161171'},{'domain':'.jd.com','expiry':1748918985,'httpOnly':False,'name':'pinId','path':'/','sameSite':'None','secure':True,'value':'YCe8rw2G6w2zBk65PfDfDg'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':False,'name':'pin','path':'/','sameSite':'None','secure':True,'value':'jd_XLCuliLsIoml'},{'domain':'.jd.com','expiry':1717386601,'httpOnly':False,'name':'jsavif','path':'/','sameSite':'Lax','secure':False,'value':'1'},{'domain':'.jd.com','expiry':1717384801,'httpOnly':False,'name':'token','path':'/','sameSite':'Lax','secure':False,'value':'58b2853fe33d43b6606c5a21df75d6e5,3,954101'},{'domain':'.jd.com','expiry':1719975003,'httpOnly':False,'name':'ipLoc-djd','path':'/','sameSite':'Lax','secure':False,'value':'25-2258-2261-6568'},{'domain':'www.jd.com','expiry':1717386590,'httpOnly':False,'name':'UseCorpPin','path':'/','sameSite':'Lax','secure':False,'value':'jd_XLCuliLsIoml'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':False,'name':'_tp','path':'/','sameSite':'None','secure':True,'value':'gcPCiSoOxTEQh1UmLWSJmA%3D%3D'},{'domain':'.jd.com','expiry':1718246952,'httpOnly':False,'name':'areaId','path':'/','sameSite':'Lax','secure':False,'value':'25'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':False,'name':'unick','path':'/','sameSite':'None','secure':True,'value':'717tjgq12eb3u3'},{'domain':'.jd.com','expiry':1717383072,'httpOnly':False,'name':'_gia_d','path':'/','sameSite':'Lax','secure':False,'value':'1'},{'domain':'.jd.com','expiry':1751942985,'httpOnly':False,'name':'TrackID','path':'/','sameSite':'None','secure':True,'value':'16Qvq9anbTkSX8gr4zaukUq5uQYslojZC9OQmewQghRGZ3XvjG_MMnzr_vyEIKSdUCtJ2wRpSFTY3eQtR-mtgEtTLaduuEqMy1V9rbOxT2sDX0aNazsKZ9ymfF8kbb66r'},{'domain':'.jd.com','expiry':1751943003,'httpOnly':False,'name':'shshshfpb','path':'/','sameSite':'Lax','secure':False,'value':'BApXcwpUJ3-pAgpgn7ERHMlecUhcGxJTHBlV5Lnto9xJ1MukUQIC2'},{'domain':'.jd.com','expiry':1751943002,'httpOnly':False,'name':'shshshfpa','path':'/','sameSite':'Lax','secure':False,'value':'52743637-1e03-a986-e555-3b60bd02251d-1717382954'},{'domain':'.jd.com','expiry':1751942954,'httpOnly':False,'name':'shshshfpx','path':'/','sameSite':'Lax','secure':False,'value':'52743637-1e03-a986-e555-3b60bd02251d-1717382954'},{'domain':'www.jd.com','expiry':1748918953,'httpOnly':False,'name':'o2State','path':'/','sameSite':'Lax','secure':False,'value':'{%22webp%22:true%2C%22avif%22:true%2C%22lastvisit%22:1717382953020}'},{'domain':'.jd.com','expiry':1718678985,'httpOnly':True,'name':'thor','path':'/','sameSite':'None','secure':True,'value':'B4C20964EEB81D93A1282B10D740DDCE93E6BF376C1A027834CA7420581040CA1F1691CE77DF8E8D4839BB18578D59CADD7B65F3464D14E69D56C466193409E2C5CC1CCC0FB0077D600F5E5A9050977080A6CD9DB54BF53D86A4A33D85C531B9CBA745CE208771BE1D5DFCEBADFD8E0CEB8C892454D65E7595BB979BE56296A5F7B62DAF0FD0D84D7FE1241F16E5B46A7A60AB7C12103EA76433421EA1F54E0A'},{'domain':'.jd.com','expiry':1743302958,'httpOnly':False,'name':'3AB9D23F7A4B3C9B','path':'/','sameSite':'Lax','secure':False,'value':'IGRRJT2FGAUX2L3XBSLXZRHOWGH7YNRHMBQHXA7OMUM75D6BQNTIV6YWQQLNKHV2URUHMEDS7BVALS47ABD56MW5TA'},{'domain':'.jd.com','expiry':1718679002,'httpOnly':True,'name':'flash','path':'/','sameSite':'None','secure':True,'value':'2_zpZqs4H7M7_a9OhxVV4eMXgMPNf1o8Lxl-gS2Cneh79n2xY8IA6o9y5JglFeAKaQiZht9zwAUXVJco4lj9A4vcdvIQiBDvy8LbsO_AFm1vttvRjlsuRLrbjHGIQSlouU9NJknNKUB8TbCWUlqFfY8wD2CdBj94DPObXyoggI_DK*'},{'domain':'.jd.com','expiry':1719974985,'httpOnly':True,'name':'_pst','path':'/','sameSite':'None','secure':True,'value':'jd_XLCuliLsIoml'},{'domain':'.jd.com','expiry':1717384801,'httpOnly':False,'name':'__tk','path':'/','sameSite':'Lax','secure':False,'value':'VnTIiUTISDSEikqDVAvHVAvJTLe5Wne3iLTHiUSFikuATcVIVkq3i2,3,954101'},{'domain':'.jd.com','expiry':1748486952,'httpOnly':False,'name':'3AB9D23F7A4B3CSS','path':'/','sameSite':'Lax','secure':False,'value':'jdd03IGRRJT2FGAUX2L3XBSLXZRHOWGH7YNRHMBQHXA7OMUM75D6BQNTIV6YWQQLNKHV2URUHMEDS7BVALS47ABD56MW5TAAAAAMP3QADWNQAAAAACGG4IYVAGJI3JMX'},{'domain':'.jd.com','expiry':1732935018,'httpOnly':False,'name':'__jdu','path':'/','sameSite':'Lax','secure':False,'value':'1717382950957103922947'},{'domain':'.jd.com','httpOnly':False,'name':'ceshi3.com','path':'/','sameSite':'None','secure':True,'value':'000'},{'domain':'.jd.com','expiry':1718678950,'httpOnly':False,'name':'__jdv','path':'/','sameSite':'Lax','secure':False,'value':'76161171|direct|-|none|-|1717382950958'}]forcookieincookies:driver.add_cookie(cookie)##driver.refresh()driver.get(url)defclick_verify():#图标点选try:##截图保存img=ImageGrab.grab(bbox=(759,421,1141,793))img.save('./sel.jpg')withopen(r'./sel.jpg','rb')asf:im=f.read()##图像识别ret=y.click_verify(image=im,verify_type="30330")print("ret="+ret)ret=str(ret)pos=ret.split(',')pos[0]=int(pos[0])pos[1]=int(pos[1])#移动鼠标到起始位置pyautogui.moveTo(pos[0]+759,pos[1]+421,duration=0.3)#按下鼠标左键pyautogui.mouseDown()#松开鼠标左键pyautogui.mouseUp()time.sleep(2)##失败再次点选click_verify()returnTrueexceptExceptionase:print('click_verifyerr:',e)returnFalsedefslide_verify():##滑块验证try:ele_big=driver.find_element(By.ID,"cpc_img")ele_small=driver.find_element(By.ID,"small_img")src_big=ele_big.get_attribute('src')#print(src_big)src_small=ele_small.get_attribute('src')#获取标准的base64字符串base64_big=src_big[22:]base64_small=src_small[22:]lo_small=[804,753]##计算缺口滑块距离ret=y.slide_verify(base64_small,base64_big)ret=int(ret)+30print(ret)##鼠标操作slide_mouse(lo_small,ret)returnTrueexceptExceptionase:print('card_slideerr:',e)##转到点选验证ret=click_verify()ifret==True:returnTrueelse:returnFalsereturnFalsedefslide_mouse(pos,distance):##滑块验证移动鼠标start_x=pos[0]start_y=pos[1]end_x=pos[0]+distanceend_y=pos[1]#移动鼠标到起始位置pyautogui.moveTo(start_x,start_y,duration=0.3)#按下鼠标左键pyautogui.mouseDown()#往右多拖到20xppyautogui.moveTo(end_x-20,end_y-20,duration=0.4)#拖回结束位置pyautogui.moveTo(end_x,end_y,duration=0.5)#松开鼠标左键pyautogui.mouseUp()if__name__=='__main__':##chromedriver.exe位置:C:\Users\Administrator\AppData\Local\Programs\Python\Python311driver=webdriver.Chrome()login(driver)time.sleep(5)##自动输入卡号driver.find_element(By.XPATH,'/html/body/div[4]/div/div/div[2]/div/div[1]/div/div/div/div/div[2]/div[2]/div[2]/input').send_keys(card_id)##点击按钮driver.execute_script('document.querySelector("#root>div:nth-child(1)>div>div>div>div>div.bind-card>div.bind-form.clearfix>div:nth-child(3)>div").click()')time.sleep(3)#滑块验证、点选验证forindexinrange(100):print('滑块验证,执行第:',index)ifnotslide_verify():breaktime.sleep(3)time.sleep(10)七、python通过selenium自动登录及轻松过滑块验证、点选验证码视频演示python通过selenium自动登录及轻松过滑块验证、点选验证码改进版视频演示_哔哩哔哩_bilibili技术支持:metabycf
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2025-1-10 05:54 , Processed in 0.777831 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表