zoukankan      html  css  js  c++  java
  • python selenium 下载滑块验证码

    #_save_url  保存路径
    def image_cj(driver, _save_url):
        try:
            _file_name = random.randint(0, 100000)
            _file_url_drop = _save_url + str(_file_name) + '背景.png'  # 滑块背景存储地址
    
            _file_url = _save_url + str(_file_name) + '验证.png'  # 滑块存储地址
    
            _pic_url_drop = driver.find_element_by_xpath('//*[@id="slideBkg"]')  # 定位滑块背景图元素
    
            mutex.acquire()
            get_pic(_pic_url_drop.get_attribute('src'), _file_url_drop)  # 根据滑块背景图的url下载图片
            time.sleep(1)
            mutex.release()
            _pic_url = driver.find_element_by_xpath('//*[@id="slideBlock"]')  # 定位滑块元素
    
            mutex.acquire()
            get_pic(_pic_url.get_attribute('src'), _file_url)  # 根据滑块的url下载图片
            time.sleep(1)
            mutex.release()
            file_path = []  # 定义滑块返回图片存储地址
    
            file_path.append(_file_url)
    
            file_path.append(_file_url_drop)
            return file_path
        except Exception as e:
            print('错误 :', e)
            return str(_file_url)
    
    #下载图片
    def get_pic(url, path):
        response = requests.get(url)
        # 获取的文本实际上是图片的二进制文本
        img = response.content
        # 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
        with open(path, 'wb') as f:
            f.write(img)
  • 相关阅读:
    网络负载均衡LVS
    JS 模仿红绿灯(控制台)
    【转】wrk 压力测试的 lua脚本
    linux开机 自动挂载和启动jar包
    【转】jprofiler linux配置需要监听的程序的端口
    时间复杂度总结
    Windows Subsystem for Linux (WSL) 安装
    敬畏用户
    Golang语言HTTP客户端实践
    Groovy入门常用语法
  • 原文地址:https://www.cnblogs.com/chenlizhi/p/12935160.html
Copyright © 2011-2022 走看看