本文实例讲述了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程序设计有所帮助。