python selenium4 模拟点击+拖动+保存验证码 测试对象+以验证码的返回ID保存命名 58同城验证码,,#!/usr/bin
python selenium4 模拟点击+拖动+保存验证码 测试对象+以验证码的返回ID保存命名 58同城验证码,,#!/usr/bin
#!/usr/bin/python# -*- coding: UTF-8 -*-# @Time : 2019/12/5 17:30# @Author : shenghao/[email protected]‘‘‘test with selenium‘s move‘‘‘from builtins import printfrom selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byimport cv2 as cvimport time, datetime, random,shutilfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.touch_actions import TouchActionsfrom selenium.webdriver.common.keys import Keysfrom PIL import Imageimport requestsfrom io import BytesIOimport cv2, time, sys,reimport matplotlib.pyplot as pltimport numpy as npclass selenium(object): def __init__(self): self.headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36"} chrome_option = webdriver.ChromeOptions() self.driver = webdriver.Chrome(executable_path="C:\Program Files\Python37\chromedriver.exe", chrome_options=chrome_option) self.driver.set_window_size(1440, 900) def visit_index(self): self.driver.get( "https://callback.58.com/antibot/verifycode?serialId=62cbf64a21ab4d309e722680c623a4e4_31ec33353c0648b7a5c97b1f2fb35976&code=22&sign=e6760461fc971994a2f3809ff536fbe9&namespace=anjuke_zufang_pc&url=.zu.anjuke.com%2Ffangyuan%2F1206610285371393%3Fisauction%3D1%26shangquan_id%3D1846") try: click_status = WebDriverWait(self.driver, 5, 1).until( EC.element_to_be_clickable((By.XPATH, "//div[@class = ‘code_num‘]/input"))).click() html = self.driver.find_element_by_xpath("//*").get_attribute("outerHTML") rid = re.search("rid=(.*?)&", html).group(1) time.sleep(1) self.save_img(rid) except: pass def save_img(self,rid): ‘‘‘//div[@class = ‘dvc-slider__handler‘] button position‘‘‘ image_name = datetime.datetime.now().timestamp() element = self.driver.find_element_by_xpath("//img[@class=‘dvc-captcha__bgImg‘]").screenshot_as_png with open(r‘./%s_%s.png‘ % (rid,image_name), ‘wb‘) as f: f.write(element) print(">>>>>>>>>>>>>>>>>>>>>> %s" % element) time.sleep(2) self.driver.close()if __name__ == ‘__main__‘: h = selenium() h.visit_index()
python selenium4 模拟点击+拖动+保存验证码 测试对象+以验证码的返回ID保存命名 58同城验证码
相关内容
- Python基础系列讲解-自动控制windows桌面,,原链接:htt
- Pycharm的安装,,由于一些原因,要在一
- Python制作有道翻译小工具,有道翻译,该工具主要是利用
- matplotlib可视化之如何给图形添加数据标签?,matplotl
- Python调用GithubAPI并进行初步的数据分析,如何数据分析
- 吴裕雄 实战PYTHON编程(9),编程,import cv2
- Python+Appium 查找 toast 方法的封装,toast,使用场景:在
- Python练习题–持续更新,,1、你是一个高级测试
- 吴裕雄 python 数据处理(1),python做数据处理,import t
- 学Python的第六天,,今天发愤图强,死学P
评论关闭