python selenium4 模拟点击+拖动+保存验证码 测试对象+以验证码的返回ID保存命名 58同城验证码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @Time    : 2019/12/5 17:30
# @Author  : shenghao/[email protected]
‘‘‘test with selenium‘s move‘‘‘
from builtins import print

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import cv2 as cv
import time, datetime, random,shutil
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.touch_actions import TouchActions
from selenium.webdriver.common.keys import Keys
from PIL import Image
import requests
from io import BytesIO
import cv2, time, sys,re
import matplotlib.pyplot as plt
import numpy as np

class 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()

原文地址:https://www.cnblogs.com/tnsay/p/12009947.html

时间: 2024-07-30 19:28:44

python selenium4 模拟点击+拖动+保存验证码 测试对象+以验证码的返回ID保存命名 58同城验证码的相关文章

python selenium3 模拟点击+拖动+保存验证码 测试对象 58同城验证码

#!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019/12/5 17:30 # @Author : shenghao/[email protected] '''test with selenium's move''' from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.

python selenium2 模拟点击+拖动 测试对象 58同城验证码

#!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019/12/5 17:30 # @Author : shenghao/[email protected] '''test with selenium's move''' from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.

python selenium5 模拟点击+拖动+按照指定相对坐标拖动 58同城验证码

#!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019年12月9日11:41:08 # @Author : shenghao/[email protected] '''test with selenium's move by x,y''' from builtins import print from selenium import webdriver from selenium.webdriver.support.ui import W

如何使用python来模拟鼠标点击(将通过实例自动化模拟在360浏览器中自动搜索"python")

一.准备工作: 安装pywin32,后面开发需要pywin32的支持,否则无法完成与windows层面相关的操作. pywin32的具体安装及注意事项: 1.整体开发环境: 基于windows7操作系统; 提前安装python(因为篇幅问题,在此不详细讲解python环境的安装,大家可以自备楼梯): 大家可以在cmd中测试下python环境是否安装好: 大家可以看到我电脑上已经安装好了Python,并显示版本与是V 3.6.2. 注:自己电脑上的Python版本号一定要知道,后面安装pywin3

python + selenium 模拟键盘升级版PyUserInput

前言在web自动化下载操作时,有时候会弹出下载框,这种下载框不属于web的页面,是没办法去定位的(有些同学一说到点击,脑袋里面就是定位!定位!定位!)有时候我们并不是非要去定位到这个按钮再去点击,学会使用键盘的快捷键操作,也能达到一样的效果.之前讲过一篇Selenium2+python自动化75-非input文件上传(SendKeys)这个当时是基于python2写的.最近很多小伙伴开始用python3了,这个SendKeys在python3上没法用,python3需要用PyUserInput,

淘宝试用 模拟点击程序

一个模拟点击事件的程序.试用python语言.循环点击淘宝试用的宝贝.由于平时中过几次淘宝试用,认为有这种机会白不用,所以自己写了个小程序,免去人为琐碎的点击申请宝贝. 代码开源在github https://github.com/Rockyzsu/TaobaoTrial

爬虫之动态HTML处理(Selenium与PhantomJS )动态页面模拟点击

动态页面模拟点击 #!/usr/bin/env python # -*- coding:utf-8 -*- # python的测试模块 import unittest from selenium import webdriver from bs4 import BeautifulSoup class douyuSelenium(unittest.TestCase): # 初始化方法 def setUp(self): self.driver = webdriver.PhantomJS() #具体的

使用python selenium-webdriver模拟博客园登录

初学python,最近在抱着虫师的python+selenium自动化的书看,也尝试写个登录功能的验证2333 code:########################## #使用python selenium-webdriver #模拟博客园的登录流程 #首页--登录页面--跳转回首页--检查--退出登录恢复环境 ########################### from selenium import webdriver import time import sys url_cnbl

爬虫——模拟点击动态页面

动态页面的模拟点击: 以斗鱼直播为例:http://www.douyu.com/directory/all 爬取每页的房间名.直播类型.主播名称.在线人数等数据,然后模拟点击下一页,继续爬取 #!/usr/bin/python3 # -*- conding:utf-8 -*- __author__ = 'mayi' """ 动态页面的模拟点击: 模拟点击斗鱼直播:http://www.douyu.com/directory/all 爬取每页房间名.直播类型.主播名称.在线人数