不花钱,模拟登录古诗中文网

import requests
from lxml import etree
import ddddocr
if __name__=="__main__":
    session = requests.Session()#用session可以模拟,但是用单纯用request不行,因为他们的区别仅仅在于requests.get每次都自动关闭连接。而session.get不关闭连接
    url = 'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36 Edg/91.0.864.48'

    }
    respone_text = session.get(url=url,headers=headers).text
    tree = etree.HTML(respone_text)
    new_url = 'https://so.gushiwen.cn' + tree.xpath('//*[@id="imgCode"]/@src')[0]
    respone_content = session.get(url=new_url,headers=headers).content
    with open('验证码图片.png', 'wb') as fp:
        fp.write(respone_content)


#ddddocr开始使用,这个库用法很多,具体看下作者的github:https://github.com/sml2h3/ddddocr
    ocr = ddddocr.DdddOcr()

    with open("./验证码图片.png", 'rb') as f:
        image = f.read()

    res = ocr.classification(image)
    print(res)
    with open('文字.txt', 'w') as fp:
        fp.write(res)


    new_tree = etree.HTML(respone_text)
    viestate = new_tree.xpath('// *[ @ id = "__VIEWSTATE"]/@value')[0]



    login_url = 'https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx'
    data = {
    '__VIEWSTATE': viestate,
    '__VIEWSTATEGENERATOR': 'C93BE1AE',
    'from': 'http: //so.gushiwen.cn/user/collect.aspx',
    'email': '1434463715@qq.com',
    'pwd': 'h18894898963',
    'code': res,
    'denglu': '登录'

    }

    login_response = session.post(url=login_url,headers=headers,data=data)
    login_response_test = login_response.text


    with open('go.html','w',encoding='utf-8') as fp:
        fp.write(login_response_test)
    print(login_response.status_code)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值