python reptile pass through the blackboard lesson - the second hurdle

 

# ! / Usr / bin / Python 
# - * - Coding: UTF-8 - * - 
# Author: LiTianle 
# Time: 2019/9/24 15:36 
'' ' 
<h3> You need to enter the URL in the digital 53639 < / h3> 
<number> you need to enter a next h3 was 10963. </ h3> 
'' ' 
Import Requests, Re
 DEF main (): 
    URL = ' http://www.heibanke.com/lesson/crawler_ex01/ ' 
    headers = {
         ' the User-- Agent ' : ' the Mozilla / 5.0 (the Windows NT 10.0; Win64; x64-) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 75.0.3770.100 Safari / 537.36 ' ,
    }
    data={'username':'litianle','password':1}
    ex='<h3>(.*)</h3>'
    for i in range(30):
        respone_page=requests.post(url=url,data={'username':'litianle','password':i}).text
        result=re.findall(ex,respone_page,re.S)[0]
        print(result,i)
        if ''Success in result:
            nex_url=re.findall('<a href="(.*)/"',respone_page,re.S)[0]
            print('下一关:'+'http://www.heibanke.com'+nex_url)
            break

if __name__ == '__main__':
    main()

 

Guess you like

Origin www.cnblogs.com/tianleblog/p/11672690.html