用Python爬取X查分
本帖最后由 ths2022 于 2022-4-21 14:34 编辑因为孩子在上高中,想知道年级前几名的成绩,所以用Python写了爬取X查分的代码。
代码如下:
import requests
import re
import ddddocr
session = requests.session()
url = 'https://xxxxxx.yichafen.com/public/checkcondition/sqcode/MsjcMn2mMzIwNHw3YjIzMGM2NTIwYjA4MzU0ZmE2Mzg3MDVkN2JmM2Q0YnwyNDQ4NDMO0O0O.html'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
'Referer': 'https://xxxxxx.yichafen.com/public/queryscore/sqcode/MsjcMn2mMzIwNHw3YjIzMGM2NTIwYjA4MzU0ZmE2Mzg3MDVkN2JmM2Q0YnwyNDQ4NDMO0O0O.html',
}
begin = 10001
for num in range(begin, 10500):
if num < begin + 4:
response = session.get(url='https://xxxxxx.yichafen.com', headers=headers)
r = session.post(url, headers=headers, data={'s_kaohao': num, 's_xingming': '姓名'})
r.raise_for_status()
str1 = re.search('姓名不正确',r.text)
if not str1:
res = session.get(url='https://xxxxxx.yichafen.com/public/queryresult.html', headers=headers)
res.raise_for_status()
print("%d right" % num)
with open('cj.html', 'wb') as ff:
for chunk in res.iter_content(100000):
ff.write(chunk)
break
else:
sdk = ddddocr.DdddOcr()
resp = session.get(url='https://xxxxxx.yichafen.com/public/verify.html', headers=headers)
image_bytes = resp.content
code = sdk.classification(image_bytes)
ra = session.post(url, headers=headers, data={'s_kaohao': num, 's_xingming': '姓名', 'verify': code})
ra.raise_for_status()
str1 = re.search('姓名不正确', ra.text)
if str1:
continue
str2 = re.search('验证码不正确', ra.text)
if str2:
print("%d 验证码不正确" % num)
continue
res = session.get(url='https://xxxxxx.yichafen.com/public/queryresult.html', headers=headers)
res.raise_for_status()
print("%d right" % num)
with open('cj.html', 'wb') as ff:
for chunk in res.iter_content(100000):
ff.write(chunk)
break
这也太卷了{:301_977:} 别人家的孩子吗?{:301_998:} 易查分可以做到吗 这个没有学生信息也能查到? 能不能加个联系方式啊 我也想查一下成绩 hhh 但是看不懂这个代码 联系ZhiXu3022
页:
[1]