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.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
import matplotlib.pyplot as plt
import numpy as np

class selenium_2_move(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()
            time.sleep(1)
            self.save_img()
        except:
            pass

    def save_img(self):
        ‘‘‘//div[@class = ‘dvc-slider__handler‘]  button position‘‘‘
        image_name = datetime.datetime.now().timestamp()
        # self.driver.save_screenshot("%s.png" % image_name)
        # print(image_name)
        element = self.driver.find_element_by_xpath("//img[@class=‘dvc-captcha__bgImg‘]").screenshot_as_png
        with open(r‘./%s.png‘ % image_name, ‘wb‘) as f:
            f.write(element)
        print(">>>>>>>>>>>>>>>>>>>>>> %s" % element)
        time.sleep(2)
        self.driver.close()

if __name__ == ‘__main__‘:
    h = selenium_2_move()
    h.visit_index()

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

时间: 2024-07-30 19:31:35

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

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 WebDriverWa

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】模拟登录上海西南某高校校园网 (jaccount)

好久没写东西了,最近学习了一下模拟登录,以校园网为例,作一记录. 去年的时候写过一篇模拟登录的文章,用的是登录后的cookies,这种操作比较傻瓜,也不智能,不够自动化,本质还是手动登录. 这次我尝试把登录过程用python进行,预先提供账号.密码即可. 众所周知(本校兄弟姐妹),本校所有身份认证现已完全由jaccount进行,只要通过了这一层验证,就相当于登录成功了. 以登录校园邮箱为例,先分析一下登录流程: 输入邮箱网址mail....edu.cn 跳转到jaccount验证页 输入账号.密

python爬虫--模拟12306登录

模拟12306登录 超级鹰: #!/usr/bin/env python # coding:utf-8 import requests from hashlib import md5 class Chaojiying_Client(object): def __init__(self, username, password, soft_id): self.username = username password = password.encode('utf8') self.password =

python爬虫scrapy框架——人工识别知乎登录知乎倒立文字验证码和数字英文验证码

目前知乎使用了点击图中倒立文字的验证码: 用户需要点击图中倒立的文字才能登录. 这个给爬虫带来了一定难度,但并非无法解决,经过一天的耐心查询,终于可以人工识别验证码并达到登录成功状态,下文将和大家一一道来. 我们学习爬虫首先就要知道浏览器给服务器传输有什么字段(我用的是Safari浏览器进行演示,当然Chrome.Firefox都可以) 我们点击了第一个和第二个文字: 右键审查元素-->点击登录 后可以看到: 从右面可以得到:报文发送的URL是:https://www/zhihu/com/log

python + selenium 模拟键盘升级版PyUserInput

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

python Tkinter接受键盘输入并保存文件

最近想用python写个切换host的小工具,折腾了好几天,终于实现了第一步. 采用Tkinter编程,text控件接受输入,然后点击save按钮,保存内容到当前文件夹下,文件名为hostb,如下两张图片: 直接上代码: #支持中文 #!coding:gbk #导入需要的包from Tkinter import *import timeimport osimport sys; #reload sysreload(sys); #设置系统的默认编码为utf8sys.setdefaultencodin