import requests
from lxml import etree
'''
黑板爬虫闯关02
网址:http://www.heibanke.com/lesson/crawler_ex01/
''' url = "http://www.heibanke.com/lesson/crawler_ex01/"
data = {
'username':"shuimo",
'password': 0,
}
for i in range(30):
data['password'] = i
res = requests.post(url,data=data)
res.encoding="utf8"
html = etree.HTML(res.content)
info = html.xpath("//h3/text()")[0][4:8]
if info != "密码错误":
url = "http://www.heibanke.com" + str(html.xpath('//a[@class="btn btn-primary"]/@href')[0])
print("下一关的网址是:%s"%url)
print("闯关成功的数字是%d"%i)
break

  

04-23 14:42
查看更多