爬虫闯关链接:http://www.heibanke.com/lesson/crawler_ex01/
知识点:Web编程,抓包,模拟post请求
参考代码:
#!/usr/bin/env python
# encoding: utf-8
import requests
import sys
import re
reload(sys)
sys.setdefaultencoding("utf-8")
password = "1"
payload = {
"csrfmiddlewaretoken": "2tPnnkChyTMW4o36jheDklAvUyPX1nhs",
"username": "a",
"password": password
}
for i in range(31):
payload["password"] = str(i) #不能直接赋值password,这样无法修改字典中的password值,必须要通过字典访问
resp = requests.post("http://www.heibanke.com/lesson/crawler_ex01/", data=payload)
text = unicode(resp.content).encode("utf8")
if text.find(u"错误".decode("utf8")) == -1:
print "[+] FOUND: "+ payload["password"]
break
else:
print payload["password"]