zoukankan      html  css  js  c++  java
  • python网络爬虫边看边学(selenium模块三验证码)

    selenium模块

    超级鹰取验证码

           1、登录超级鹰(http://www.chaojiying.com/),点击“用户登录”,输入用户名和密码登录。

           2、点击左侧的“软件ID”栏目,点击“生成一个软件ID”,名称任意,软件ID请记住。

           3、点击频道“开发文档”,选择“python”,点击“点击这里下载”。

           4、解压,选择图片和python文件,放入项目中。

           5、修改python文件:if __name__=="__main__":    a、缩进  b、python语句  c、chaojiying_client(参数)

    chaojiying.py文件

    #!/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 = md5(password).hexdigest()
            self.soft_id = soft_id
            self.base_params = {
                'user': self.username,
                'pass2': self.password,
                'softid': self.soft_id,
            }
            self.headers = {
                'Connection': 'Keep-Alive',
                'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
            }
    
        def PostPic(self, im, codetype):
            """
            im: 图片字节
            codetype: 题目类型 参考 http://www.chaojiying.com/price.html
            """
            params = {
                'codetype': codetype,
            }
            params.update(self.base_params)
            files = {'userfile': ('ccc.jpg', im)}
            r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
            return r.json()
    
        def ReportError(self, im_id):
            """
            im_id:报错题目的图片ID
            """
            params = {
                'id': im_id,
            }
            params.update(self.base_params)
            r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
            return r.json()
    
    
    if __name__ == '__main__':
        chaojiying = Chaojiying_Client('735388881', '6715258', '915278')	# 用户中心>>软件ID 生成一个替换 96001
        im = open('a.jpg', 'rb').read()							# 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
        print(chaojiying.PostPic(im, 1902))				# 1902 验证码类型  官方网站>>价格体系 3.4+版 print 后要加()
    

      

    超级鹰登录验证码

    from selenium.webdriver import Chrome
    from chaojiying import Chaojiying_Client
    import time
    
    web=Chrome()
    
    web.get('http://www.chaojiying.com/user/login/')
    
    img=web.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png
    
    chaojiying = Chaojiying_Client('735388881', '6715258', '915278')  # 用户中心>>软件ID 生成一个替换 96001
    
    dic=chaojiying.PostPic(img,1902)
    
    verify_code=dic['pic_str']
    
    #向页面填入用户名,密码,验证码
    web.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys('735388881')
    web.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys('6715258')
    web.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(verify_code)
    time.sleep(5)
    #点击登录
    
    web.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click()
    

      

  • 相关阅读:
    批处理压缩iis日志
    centos6 安装wkhtmltopdf 生成pdf
    SpringMVC
    MVC的了解
    Eclipse创建SpringMVC,Spring, Hibernate项目
    mysql表基本查询
    JVM垃圾回收机制与内存回收
    mysql外键(Foreign Key)的使用
    MyEclipse做的项目改成eclipse能用的
    invalid location of tag 解决办法
  • 原文地址:https://www.cnblogs.com/shixiaoxun/p/14663982.html
Copyright © 2011-2022 走看看