|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Stubborn 于 2019-4-14 04:11 编辑
看了代码,你也许会的好傻,哈哈,我也觉得是,请跳过,嘿,看下验证码啊! 这个辣眼的提示
- # -*- coding: utf-8 -*-
- # @Time : 2019-04-10 14:47
- # @Author : Ein
- # @File : tesserocr验证码识别-古诗文.py
- # @Software: PyCharm
- '''
- g1RRZ+h02qqY4rNct0PPw/ELkgPaoF82SoPcA8lIEM2q0bQsHXhB6ANpGwCX25N5r3jqUq9XpNkweWhcQD7j1iaAp4kG4xG48jx3iow1bBtRhU+9fqw1Y/Tp3g0=
- C93BE1AE
- '''
- import requests,os
- from lxml import etree
- def yzm_file_path():
- currrent_path = os.path.realpath(__file__) # 文件绝对路径
- current_dir = os.path.split(currrent_path)[0]
- return current_dir + r"/yzm.jpg"
- def down_html():
- currrent_path = os.path.realpath(__file__) # 文件绝对路径
- current_dir = os.path.split(currrent_path)[0]
- return current_dir + r"/htj.html"
- headers = {
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
- }
- session = requests.Session()
- def download_yzm():
- url = 'https://so.gushiwen.org/user/login.aspx?from='
- resp = session.get(url=url,headers=headers).text
- tree = etree.HTML(resp)
- #图片地址:
- img_url = 'https://so.gushiwen.org' + tree.xpath("//img[@id='imgCode']/@src")[0]
- #获取验证码令牌
- VIEWSTATE = tree.xpath("//input[@type='hidden'][1]/@value")[0]
- VIEWSTATEGENERATOR = tree.xpath("//input[@type='hidden'][1]/@value")[1]
- #下载到本地
- response = session.get(url=img_url,headers=headers)
- yzm_path = yzm_file_path()
- with open(yzm_path, "wb") as f:
- f.write(response.content)
- return VIEWSTATE,VIEWSTATEGENERATOR
- def poss_pwd(vi,vie):
- pwd_url = 'https://so.gushiwen.org/user/login.aspx?from=http%3a%2f%2fso.gushiwen.org%2fuser%2fcollect.aspx'
- yzm = input("嘿,看下验证码啊!=")
- data = {
- '__VIEWSTATE': vi,
- '__VIEWSTATEGENERATOR': vie,
- 'from':'http://so.gushiwen.org/user/collect.aspx',
- 'email':'812745685@qq.com',
- 'pwd': 'asd123..',
- 'code': yzm,
- 'denglu': '登录',
- }
- path = down_html()
- response = session.post(url=pwd_url,data=data)
- with open(path,'w',encoding='utf8') as fp:
- fp.write(response.text)
- def main():
- vi,vie = download_yzm()
- poss_pwd(vi,vie)
- if __name__ == '__main__':
- main()
复制代码 |
评分
-
查看全部评分
|