本文實例講述了python抓取百度首頁的方法。分享給大家供大家參考。具體實現方法如下:
import urllibdef downURL(url,filename): try: fp=urllib.urlopen(url) except: print('download error') return 0 op=open(filename,'wb') while 1: s=fp.read() if not s: break op.write(s) fp.close() op.close() return 1downURL("http://www.baidu.com","C://url.txt")
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答