古诗文网登录代码:
# 古诗文网登录实战
# 验证码链接:https://so.gushiwen.cn/RandCode.ashx
# 变动参数链接:__VIEWSTATE所在的地址:https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx
# 登录接口链接:https://so.gushiwen.cn/user/login.aspx
import requests
import ddddocr
import re
url = 'https://so.gushiwen.cn/RandCode.ashx'
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
session = requests.Session()
response = session.get(url=url,headers=headers).content # 访问验证码链接
ocr = ddddocr.DdddOcr(show_ad=False)
code = ocr.classification(response) # 获取验证码
print(code)
response = session.get(url='https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx',headers = headers).text
__VIEWSTATE = re.findall('id="__VIEWSTATE" value="(.*?)" />',response)[0] # 利用正则获取__VIEWSTATE参数的值
print(__VIEWSTATE)
login_url = 'https://so.gushiwen.cn/user/login.aspx'
params = {
'__VIEWSTATE': __VIEWSTATE,
'__VIEWSTATEGENERATOR': ' C93BE1AE',
'from': ' http://so.gushiwen.cn/user/collect.aspx',
'email': ' 18720180853',
'pwd': ' 20010119yx',
'code': code,
'denglu': ' 登录',
}
result = session.post(url=login_url,data=params,headers=headers).text
print(result)
session.close()
结果展现:
网址:aHR0cHM6Ly9qenNjLmpzdC56ai5nb3YuY24vUHVibGljV2ViL2luZGV4Lmh0bWwjLw==
进入页面刷新,会出现验证码验证。找到获取验证码的接口,以及发送信息的接口,进行实战。
# 获取验证码的链接
# https://jzsc.jst.zj.gov.cn/publishserver/OTMqtzgjpvnsrtun/OTMnyrbpdic
# 验证码验证链接 https://jzsc.jst.zj.gov.cn/publishserver/OTMqtzgjpvnsrtun/OTModijfnUjrdxxs
import requests
import ddddocr
url = 'https://jzsc.jst.zj.gov.cn/publishserver/OTMqtzgjpvnsrtun/OTMnyrbpdic'
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
session = requests.Session()
response = session.get(url=url,headers=headers).content
ocr = ddddocr.DdddOcr(beta=False,show_ad=False)
code = ocr.classification(response)
print(code)
verify_url = 'https://jzsc.jst.zj.gov.cn/publishserver/OTMqtzgjpvnsrtun/OTModijfnUjrdxxs'
params = {
'verificationCode': code
}
result = session.get(url=verify_url,headers=headers,params=params)
print(result.text)
session.close()
结果为: