Python:黑板课爬虫闯关第二关
2021-06-27 23:04
标签:test http 分享图片 group name arch bsp pos 简单 第二关依然是非常的简单 Python:黑板课爬虫闯关第二关 标签:test http 分享图片 group name arch bsp pos 简单 原文地址:https://www.cnblogs.com/gl1573/p/9650920.html枚举密码循环 post 请求,直到密码正确
import re
import requests
import time
def main():
url = ‘http://www.heibanke.com/lesson/crawler_ex01/‘
for psd in range(30):
print(f‘test password {psd}‘)
r = requests.post(url, data={‘username‘: ‘aa‘, ‘password‘: psd})
html = r.text
if ‘密码错误‘ not in html:
m = re.search(‘(?).*?(?=\\>)‘, html)
print(m.group())
m = re.search(‘(\下一关\)‘, html)
print(f‘下一关 http://www.heibanke.com{m.group(2)}‘)
return
else:
time.sleep(1)
if __name__ == ‘__main__‘:
main()