当前位置: 首页 > news >正文

徐州网站开发常用网站png

徐州网站开发,常用网站png,哪个云服务器便宜又好,微信如何开公众号selenium实战之模拟登录b站 基础知识铺垫#xff1a; 利用selenium进行截图#xff1a; driver.save_screenshot() 注意图片文件名要用png结尾. 关于移动#xff1a; ActionChains(bro).move_to_element_with_offset()# 对于某个图像ActionChains(bro).move_by_offset(…selenium实战之模拟登录b站 基础知识铺垫 利用selenium进行截图 driver.save_screenshot() 注意图片文件名要用png结尾. 关于移动 ActionChains(bro).move_to_element_with_offset()# 对于某个图像ActionChains(bro).move_by_offset()# 相对于相对位置ActionChains(bro).move_to_element() # 直接滑动到另一个位置 from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager path rD:\Downloads\xx\chromedriver-win64\chromedriver.exe driver webdriver.Chrome(executable_pathpath) login_url https://www.baidu.com driver.get(login_url) driver.save_screenshot(./img/baidu.png)driver.quit()思路 登录接口 https://passport.bilibili.com/login首先需要点击密码登录找到账号的输入框输入账号找到密码输入框输入密码找到登录按钮点击登录、 其实第一步不用做因为我们发现打开这个网页默认是使用密码登录。 同样找到密码的输入框 找到登录按钮的位置 然后会弹出验证码点选择框。 注意要将这个点选择框全部包括这里的xpath只能手写因为你发现存在iframe标签。 code_tag bro.find_element_by_xpath(//div[classgeetest_panel geetest_wind]//div[classgeetest_widget])找到对应的标签后调用截图函数保存在本地交给第三方打码平台。 # #使用图鉴接口识别 result tujian.getImgCodeText(./code.png,27)#获取了识别的结果大坑 到了最重要的时候了根据第三方平台提供的坐标点选验证码下面有四种写法只有第一种和第四种是对的. 第一种 for pos in result_list:x int(pos.split(,)[0])y int(pos.split(,)[1])ActionChains(bro).move_to_element_with_offset(code_tag,x,y).click().perform()#sleep(0.5)ActionChains(bro).pause(1).perform()第二种 每一次创建的动作连都是匿名函数类型影响最小。 for pos in result_list:x int(pos.split(,)[0])y int(pos.split(,)[1])# 创建一个ActionChains实例actions ActionChains(bro)# 执行操作actions.move_to_element_with_offset(code_tag, x, y).click().perform()# 添加暂停时间actions.pause(1).perform()​ 错误原因每次迭代都创建了一个新的ActionChains实例并在该实例上执行操作和添加暂停时间。这样的操作会导致每次迭代都是独立的操作它们之间没有建立起连续的操作序列。 第三种 demoActionChains(bro) for pos in result_list:x int(pos.split(,)[0])y int(pos.split(,)[1])demo.move_to_element_with_offset(code_tag,x,y).click().perform()#sleep(0.5)demo.pause(1).perform()错误原因每个perform()方法只会执行之前添加的一系列操作而不会执行之后添加的操作 在使用ActionChains时通常是在添加完所有操作后调用一次perform()来执行操作序列。不需要在每个操作后都调用perform()。 第四种 demo ActionChains(bro)for pos in result_list:x int(pos.split(,)[0])y int(pos.split(,)[1])demo.move_to_element_with_offset(code_tag, x, y).click()demo.pause(1) # 执行所有操作 demo.perform()​ 我们在循环之前创建了一个单独的ActionChains实例demo。在每次迭代中我们使用该实例执行移动鼠标到指定位置并点击的操作然后添加暂停时间。这样所有的操作都被添加到了同一个ActionChains实例的操作序列中。 最后调用demo.perform()方法会执行所有的操作实现连续的验证码点击操作。 代码 from selenium import webdriver from selenium.webdriver import ActionChains from time import sleep import tujian path rD:\Downloads\xx\chromedriver-win64\chromedriver.exe # 1.创建浏览器对象 bro webdriver.Chrome(executable_pathpath) # 2.发起请求 login_url https://passport.bilibili.com/login bro.get(login_url) sleep(1) # 3.定位到指定标签填充用户名和密码 user_box bro.find_element_by_xpath(//*[idapp]/div[2]/div[2]/div[3]/div[2]/div[1]/div[1]/input) user_box.send_keys(username) sleep(1) pwd_box bro.find_element_by_xpath(//*[idapp]/div[2]/div[2]/div[3]/div[2]/div[1]/div[3]/input) pwd_box.send_keys(mima) sleep(1) login_btn bro.find_element_by_xpath(//*[idapp]/div[2]/div[2]/div[3]/div[2]/div[2]/div[2]) login_btn.click() sleep(1)# 4.定位完整的验证码对话框 # 注意在开发者工具中是可以定位到多个div表示验证码对话框的因此将这几个div都定位到以此去尝试 code_tag bro.find_element_by_xpath(//div[classgeetest_panel geetest_wind]//div[classgeetest_widget]) tagbro.find_element_by_class_name(geetest_widget)sleep(1) print(code_tag) print(tag)#5.识别验证码使用打码平台进行验证码识别 code_tag.screenshot(./code.png)#将验证码对话框截图保存 sleep(1) # #使用图鉴接口识别 result tujian.getImgCodeText(./code.png,27)#获取了识别的结果 # 几个字几个坐标 # # result 154,251|145,167 print(result) result_list result.split(|) print(结果列表为,result_list) # #result_list [154,251,145,167] # #6.根据识别出验证码的结果进行处理for pos in result_list:x int(pos.split(,)[0])y int(pos.split(,)[1])ActionChains(bro).move_to_element_with_offset(code_tag,x,y).click().perform()#sleep(0.5)ActionChains(bro).pause(1).perform()# # demo ActionChains(bro) # # for pos in result_list: # x int(pos.split(,)[0]) # y int(pos.split(,)[1]) # demo.move_to_element_with_offset(code_tag, x, y).click() # demo.pause(1) # # # 执行所有操作 # demo.perform()# ActionChains(bro).move_to_element_with_offset()# 对于某个图像 # ActionChains(bro).move_by_offset()# 相对于相对位置 # ActionChains(bro).move_to_element() # 直接滑动到另一个位置confirm_btn bro.find_element_by_xpath(//div[classgeetest_panel geetest_wind]//div[classgeetest_widget]/div[classgeetest_panel]/a/div) confirm_btn.click() sleep(50) bro.quit() 总结 在使用ActionChains类时通常在添加完所有操作后才调用perform()方法来执行操作序列。
http://www.zqtcl.cn/news/833863/

相关文章:

  • 编写网站 语言微网站开发语言
  • 深圳网站建设优化网站建设与维护培训
  • 张家港网站开发wordpress后台登录地址改
  • 郑州做网站的公司哪家好做网站运营工资是不是很低
  • 做网站电销公司开发个网站怎么做
  • 廊坊做网站哪家好深圳快速网站制
  • 网站开发文档实训小结与讨论做网站建设业务员好吗
  • 网站开发知识产权归属好看的个人网站设计
  • 怎么学习企业网站维护江西省城乡建设培训网站官方网站
  • 电脑网站 源码php网站数据库修改
  • 做网站系统的答辩ppt范文商品关键词优化的方法
  • 长沙网站设计公司怎么样如何在网站上推广自己的产品
  • 龙岗网站设计农业网站模板WordPress
  • 摄像头监控设备企业网站模板聊城网站设计公司
  • 做英文网站賺钱建筑设计资料网站
  • 上海专业网站建设平台百度sem认证
  • 个人房产查询系统网站官网推广普通话 奋进新征程
  • 网站设计理念介绍石家庄业之峰装饰公司怎么样
  • 博乐建设工程信息网站ppt软件下载免费版
  • 宿州公司网站建设企业管理培训课程讲座大全
  • 企业网站营销的优缺点Vs做的网站调试时如何适应网页
  • 策划案网站构成怎么写wordpress建个人博客
  • 自己做的网站别人怎么访问美容行业网站建设多少价格
  • 网站建设与运营 教材 崔海口个人建站模板
  • 做本地网站赚钱吗wordpress桌面宠物
  • 滁州市城市建设投资有限公司网站云服务器里面做网站播放器
  • 做yy头像的网站口碑营销案例简短
  • 卖灯杆的做网站好网页ip代理
  • 做网站开发工具哪个好网络协议分析课程设计报告
  • 如何进行营销型企业网站的优化网站开发有很多种吗