工欲善其事, its prerequisite. Can websites only be accessed interactively? Of course not, as a network of the wild World of a swordsman, old black to develop the sword of freedom, hehe, is to write code can automatically log on the system tools to obtain the desired data.
Simple version:
Sample website:
Score System: http://jwc.ecjtu.jx.cn/mis_o/login.htm
Account Number: JWC
Password: JWC
now! Let ' s go! Go! Go!
S1: Get the actual landing URL, old black used the firefox,live HTTP Headers tool, fill in the account password, get to the actual landing URL for http://jwc.ecjtu.jx.cn/mis_o/ Login.php,post Information for: USER=JWC&PASS=JWC&SUBMIT=%CC%E1%BD%BB
S2: Write python code simulation login, use Python requests
1 #-*-coding:utf-8-*-2 ImportSYS3 ImportRequests4 Reload (SYS)5Sys.setdefaultencoding ('UTF8')6 7URL ='http://jwc.ecjtu.jx.cn/mis_o/login.php'8 #1:get 2:post9option ='2'Ten ifoption = ='1': OneURL ='http://www.kfzhongzhou.com/cyjb_xx.asp?id=15' A -output_file = open ('D:\codehub\output.html','W') -Datas = {'User':'JWC', the 'Pass':'JWC', - 'Submit':'%CC%E1%BD%BB' - } -headers = {'Referer':'http://jwc.ecjtu.jx.cn/mis_o/login.php', + 'user-agent':'mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36' - '(khtml, like Gecko) chrome/52.0.2743.82 safari/537.36', + 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', A 'Accept-language':'zh-cn,zh;q=0.8', at } - if __name__=='__main__': - Print 'Get started! ' -responses =None -Sessions =requests.session () - ifoption = ='1': inresponses =sessions.get (URL) - Else: toresponses = sessions.post (URL, headers=headers, data=datas) + Printresponses.headers - PrintResponses.status_code the *r2 = Sessions.get ('http://jwc.ecjtu.jx.cn/mis_o/main.php') $Context =R2.textPanax Notoginseng output_file.write (context) - Print 'End it! ' theOutput_file.close ()
Explanation: Constructs the sessions to log in, guarantees can download the normal login to be able to visit the Tao's main.php page, verifies whether the landing succeeds.
S3: Effect, main.php content is written in the local file output.html, with Firefox open after the following effect
Because this system coding problem causes the content that writes output.html is garbled, compares the normal landing page, can see is the landing succeeds.
Extension: After optimization, you can use cookies to login, refer to the article address
"20171104 early" Python crawler's Username,password landing