python抓取百度首页的方法

yipeiwu_com6年前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程序设计有所帮助。

相关文章

python实现多线程抓取知乎用户

python实现多线程抓取知乎用户

需要用到的包: beautifulsoup4 html5lib image requests redis PyMySQL pip安装所有依赖包: pip install \...

Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】

Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】

本文实例讲述了Python3爬虫爬取英雄联盟高清桌面壁纸功能。分享给大家供大家参考,具体如下: 使用Scrapy爬虫抓取英雄联盟高清桌面壁纸 源码地址:https://github.co...

python爬取网易云音乐评论

本文实例为大家分享了python爬取网易云音乐评论的具体代码,供大家参考,具体内容如下 import requests import bs4 import json def g...

python爬虫URL重试机制的实现方法(python2.7以及python3.5)

应用场景: 状态不是200的URL重试多次 代码比较简单还有部分注释 python2.7实现: # -*-coding:utf-8-*- """ ayou """ import...

python实现爬取千万淘宝商品的方法

本文实例讲述了python实现爬取千万淘宝商品的方法。分享给大家供大家参考。具体实现方法如下: import time import leveldb from urllib.pars...