zoukankan      html  css  js  c++  java
  • python selenium3 模拟点击+拖动+保存验证码 测试对象 58同城验证码

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    # @Time    : 2019/12/5 17:30
    # @Author  : shenghao/10347899@qq.com
    '''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 FilesPython37chromedriver.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()
  • 相关阅读:
    算法导论(第三版)Exercises2.1(插入排序、线性查找、N位大数相加)
    含铝馒头可能损伤儿童的智力
    每秒3600乘以100等于36万次售票解决方案
    namespace Measure
    public interface ICloneable
    VB.net 与线程
    C#调用VP 包含素材
    C# 定时器 一个简单 并且可以直接运行的Demo
    松下 激光位移传感器 API
    在Win7系统下, 使用VS2015 打开带有日文注释程序出现乱码的解决方案
  • 原文地址:https://www.cnblogs.com/tnsay/p/12009943.html
Copyright © 2011-2022 走看看