本文實例講述了Python實現的下載網頁源碼功能。分享給大家供大家參考,具體如下:
#!/usr/bin/pythonimport httplibhttpconn = httplib.HTTPConnection("www.baidu.com")httpconn.request("GET", "/index.html")resp = httpconn.getresponse()if resp.reason == "OK": resp_data = resp.read() print resp_data print len(resp_data)httpconn.close()要下載的網頁源碼被讀取到了resp_data中了
運行效果圖如下:

希望本文所述對大家Python程序設計有所幫助。
新聞熱點
疑難解答