本文實(shí)例講述了Python實(shí)現(xiàn)的下載網(wǎng)頁(yè)源碼功能。分享給大家供大家參考,具體如下:
#!/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()要下載的網(wǎng)頁(yè)源碼被讀取到了resp_data中了
運(yùn)行效果圖如下:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python進(jìn)程與線程操作技巧總結(jié)》、《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選