python 爬虫-1:下载网页源代码
2017-08-07 09:42
218 查看
下载静态网页源代码的 python 爬虫函数源代码:
其中 url 即为你想现在的网页地址。 num_reties 为遇到 5xx 错误的时候,重试下载的次数。
具体详见我的博客:
www.wangs0622.com
import urllib2 def download(url, num_retries = 5): ''' function: 下载网页源代码,如果遇到 5xx 错误状态,则继续尝试下载,直到下载 num_retries 次为止。 ''' print "downloading " , url try: html = urllib2.urlopen(url).read() except urllib2.URLError as e: print "download error: " , e.reason html = None if num_retries > 0: if hasattr(e,'code') and 500 <= e.code < 600: return download(url, num_retries-1) return html
其中 url 即为你想现在的网页地址。 num_reties 为遇到 5xx 错误的时候,重试下载的次数。
具体详见我的博客:
www.wangs0622.com
相关文章推荐
- python爬虫一:必应图片(从网页源代码中找出图片链接然后下载)
- Python 网络爬虫 009 (编程) 通过正则表达式来获取一个网页中的所有的URL链接,并下载这些URL链接的源代码
- Python 网络爬虫 009 (编程) 通过正则表达式来获取一个网页中的所有的URL链接,并下载这些URL链接的源代码
- python3爬虫下载网页上的pdf
- python --网页爬虫,文本处理,科学计算,机器学习,数据挖掘资料+附带工具包下载
- 用python写网络爬虫-下载网页
- python 网页爬虫,下载网络图片
- python 爬虫(xpath解析网页,下载照片)
- python3爬虫1--简单网页源代码获取
- 非常全面到位的介绍与源代码地址 :Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
- python --网页爬虫,文本处理,科学计算,机器学习,数据挖掘资料+附带工具包下载+tensorflow
- python开发爬虫----urllib2下载网页方法
- python爬虫(1)下载任意网页图片
- Python3.x爬虫下载网页图片的实例讲解
- 关于python 3 和python 2的网页爬虫下载问题
- python3 网页爬虫图片下载无效链接处理 try except
- python爬虫入门篇------爬取网页源代码
- Python 网络爬虫 005 (编程) 如何编写一个可以 下载(或叫:爬取)一个网页 的网络爬虫
- Python 爬虫5——爬取并下载网页指定规格的图片
- Scrapy:Python实现scrapy框架爬虫两个网址下载网页内容信息——Jason niu