黑板客爬虫闯关第二关成功后的页面:
http://www.heibanke.com/accounts/login/?next=/lesson/crawler_ex02/
需要注册,注册后登陆:
来到这个站点:
http://www.heibanke.com/lesson/crawler_ex02/
#coding=utf-8
import requests
if __name__=='__main__':
source_url = "http://www.heibanke.com/accounts/login/?next=/lesson/crawler_ex02/"
dst_url = "http://www.heibanke.com/lesson/crawler_ex02/"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0'}
session = requests.Session() #保持登陆状态
session.get(source_url)
csrftoken = session.cookies.get('csrftoken')
data = {"username":"admin523176585",
"password":"123456",
"csrfmiddlewaretoken":csrftoken,}
session.post(source_url,data = data,headers = headers) #登陆
for pwd in range(1,30):
session.post(dst_url)
csrftoken = session.cookies.get('csrftoken')
data = {"username":"admin",
"password":pwd,
"csrfmiddlewaretoken":csrftoken,}
response = session.post(dst_url,data = data,headers = headers).text
if "密码错误" in response:
continue
print ("pwd:{}".format(pwd))