网络编程
位置:首页>> 网络编程>> Python编程>> python抓取百度首页的方法

python抓取百度首页的方法

作者:MXi4oyu  发布时间:2023-05-25 13:31:58 

标签:python,抓取

本文实例讲述了python抓取百度首页的方法。分享给大家供大家参考。具体实现方法如下:


import urllib
def 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 1
downURL("http://www.baidu.com","C:\\url.txt")

希望本文所述对大家的Python程序设计有所帮助。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com