鱼C论坛

 找回密码
 立即注册
查看: 1897|回复: 1

[作品展示] 爬虫验证码识别-01--古诗词登录

[复制链接]
发表于 2019-4-14 04:10:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Stubborn 于 2019-4-14 04:11 编辑

看了代码,你也许会的好傻,哈哈,我也觉得是,请跳过,嘿,看下验证码啊!  这个辣眼的提示
  1. # -*- coding: utf-8 -*-
  2. # @Time    : 2019-04-10 14:47
  3. # @Author  : Ein
  4. # @File    : tesserocr验证码识别-古诗文.py
  5. # @Software: PyCharm
  6. '''
  7. g1RRZ+h02qqY4rNct0PPw/ELkgPaoF82SoPcA8lIEM2q0bQsHXhB6ANpGwCX25N5r3jqUq9XpNkweWhcQD7j1iaAp4kG4xG48jx3iow1bBtRhU+9fqw1Y/Tp3g0=
  8. C93BE1AE
  9. '''

  10. import requests,os
  11. from lxml import etree
  12. def yzm_file_path():
  13.     currrent_path = os.path.realpath(__file__)  # 文件绝对路径
  14.     current_dir = os.path.split(currrent_path)[0]
  15.     return current_dir + r"/yzm.jpg"
  16. def down_html():
  17.     currrent_path = os.path.realpath(__file__)  # 文件绝对路径
  18.     current_dir = os.path.split(currrent_path)[0]
  19.     return current_dir + r"/htj.html"

  20. headers = {
  21.     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
  22. }
  23. session = requests.Session()

  24. def download_yzm():
  25.     url = 'https://so.gushiwen.org/user/login.aspx?from='
  26.     resp = session.get(url=url,headers=headers).text
  27.     tree = etree.HTML(resp)
  28.     #图片地址:
  29.     img_url = 'https://so.gushiwen.org' + tree.xpath("//img[@id='imgCode']/@src")[0]
  30.     #获取验证码令牌
  31.     VIEWSTATE = tree.xpath("//input[@type='hidden'][1]/@value")[0]
  32.     VIEWSTATEGENERATOR = tree.xpath("//input[@type='hidden'][1]/@value")[1]
  33.     #下载到本地
  34.     response = session.get(url=img_url,headers=headers)
  35.     yzm_path = yzm_file_path()
  36.     with open(yzm_path, "wb") as f:
  37.         f.write(response.content)
  38.     return VIEWSTATE,VIEWSTATEGENERATOR

  39. def poss_pwd(vi,vie):
  40.     pwd_url = 'https://so.gushiwen.org/user/login.aspx?from=http%3a%2f%2fso.gushiwen.org%2fuser%2fcollect.aspx'
  41.     yzm = input("嘿,看下验证码啊!=")
  42.     data = {
  43.         '__VIEWSTATE': vi,
  44.         '__VIEWSTATEGENERATOR': vie,
  45.         'from':'http://so.gushiwen.org/user/collect.aspx',
  46.         'email':'812745685@qq.com',
  47.         'pwd': 'asd123..',
  48.         'code': yzm,
  49.         'denglu': '登录',
  50.     }
  51.     path = down_html()
  52.     response = session.post(url=pwd_url,data=data)
  53.     with open(path,'w',encoding='utf8') as fp:
  54.         fp.write(response.text)


  55. def main():
  56.     vi,vie = download_yzm()
  57.     poss_pwd(vi,vie)

  58. if __name__ == '__main__':
  59.     main()
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
kaohsing + 1 + 1 感谢楼主无私奉献!

查看全部评分

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-17 21:56:00 From FishC Mobile | 显示全部楼层
你好,可以加个好友交流一下吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-26 06:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表