需要注册登录一下
import requests
url = 'http://www.heibanke.com/lesson/crawler_ex02/'
headers = {
"Host": "www.heibanke.com",
"Connection": "keep-alive",
"Content-Length": "80",
"Cache-Control": "max-age=0",
"Origin": "http://www.heibanke.com",
"Upgrade-Insecure-Requests": "1",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Referer": "http://www.heibanke.com/lesson/crawler_ex02/",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh,zh-CN;q=0.9,en;q=0.8",
"Cookie": "Hm_lvt_74e694103cf02b31b28db0a346da0b6b=1560757431; sessionid=8b68mgloyia36ecle55lbupcr4ifairx; csrftoken=oragp4ndPhp1reUDGBgRzzHO70FwYp6n; Hm_lpvt_74e694103cf02b31b28db0a346da0b6b=1560935517",
}
for i in range(30):
data={
'csrfmiddlewaretoken': 'oragp4ndPhp1reUDGBgRzzHO70FwYp6n',
'username': 'Test_c',
'password': i,
}
html = requests.post(url,data=data,headers=headers)
print('index',i)
if '密码错误' in html.text:
print('密码错误')
else:
print(html.text)
print('密码是:',i)
break