zoukankan      html  css  js  c++  java
  • selenium验证码pic处理代码,以91家纺网为例

    # encoding:utf-8
    from PIL import Image
    from selenium import webdriver
    from selenium.webdriver import ActionChains

    chrome_options = webdriver.ChromeOptions()
    path = r'D:project_91jiafangwanchromedriver.exe'
    browser = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)

    url = 'http://www.91jf.com/default.php?url=member&act=memberinfo'
    browser.maximize_window()  # 将浏览器最大化
    browser.get(url)

    slider = browser.find_element_by_xpath("//img[@onclick='show_user_login()']")
    ActionChains(browser).click(slider).perform()
    ActionChains(browser).release().perform()

    # 截取当前网页并放到E盘下命名为printscreen,该网页有我们需要的验证码
    browser.save_screenshot('D:\printscreen.png') 
    imgelement = browser.find_element_by_xpath("//img[@src='default.php?act=code']")  # 定位验证码
    location = imgelement.location  # 获取验证码x,y轴坐标
    size = imgelement.size  # 获取验证码的长宽
    rangle = (int(location['x']), int(location['y']), int(location['x'] + size['width']),
              int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
    i = Image.open("D:\printscreen.png")  # 打开截图
    frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
    frame4 = frame4.convert('RGB')
    frame4.save('D:\save.jpg') # 保存我们接下来的验证码图片 进行打码
    #browser.close()
  • 相关阅读:
    mysql中delimiter
    error: unpacking of archive failed on file /usr/sbin/zabbix_agent;592e5bc3: cpio: open
    CefSharp中文帮助文档
    ASP.NET Aries 开发框架
    简洁的富文本编辑器
    asp.net core 获取appsettings.json里的配置
    在asp.net core中使用NLog
    临时禁用Resharper
    visual studio 无添加视图 选项
    visual studio(vs)初始化
  • 原文地址:https://www.cnblogs.com/dog-and-cat/p/13321179.html
Copyright © 2011-2022 走看看