# -*- coding: utf-8 -*-

'''
Created on 2019年4月27日 @author: lenovo
''' # import urllib3
# def download(url):
# return urllib3.connection_from_url(url)
#
# print(download('http://now.qq.com')) # 在python中,urllib2被urllib。request所取代 # import urllib.request
# def download(url):
# return urllib.request.urlopen(url).read()
#
# print(download('https://baijiahao.baidu.com/s?id=1632775818269407606&wfr=spider&for=pc')) # import urllib.request
# def download(url):
# print("Downloading:" + url)
# try:
# html = urllib.request.urlopen(url).read()
# except urllib.request.URLError as e:
# print("Download error:" , e.reason)
# html = None
# return html
#
# print(download("htp://www.baidu.co")) # import urllib.request
# def download(url, num_retries=2):
# try:
# html = urllib.request.urlopen(url).read()
# except urllib.request.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
#
# # print(download("http://httpstat.us/500"))
# print(download("http://www.meetup.com/")) import urllib.request
def download(url, user_agent="wswp",num_retries=2):
print("Downloading: " , url)
headers = { 'User-agent': user_agent}
request = urllib.request.Request(url, headers=headers)
try:
html = urllib.request.urlopen(request).read()
except urllib.request.URLError as e:
print('Download error:' , e.reason)
html = None
if num_retries > 1 :
if hasattr(e, 'code') and 500 <= e.code < 600:
return download(url, user_agent, num_retries-1)
return html print(download("http://www.meetup.com/"))

1.4.1python下载网页(每天一更)的更多相关文章

  1. C# 网络编程之webBrowser获取网页url和下载网页中图片

    该文章主要是通过C#网络编程的webBrowser获取网页中的url并简单的尝试瞎子啊网页中的图片,主要是为以后网络开发的基础学习.其中主要的通过应用程序结合网页知识.正则表达式实现浏览.获取url. ...

  2. Python下载网页的几种方法

    get和post方式总结 get方式:以URL字串本身传递数据参数,在服务器端可以从'QUERY_STRING'这个变量中直接读取,效率较高,但缺乏安全性,也无法来处理复杂的数据(只能是字符串,比如在 ...

  3. JavaWeb学习之转发和重定向、会话技术:cookie、session、验证码实例、URLConnection使用(下载网页)(4)

    1.转发和重定向 HttpServletResponse response 转发: RequestDispatcher dispatcher = request.getRequestDispatche ...

  4. windows phone 7,sliverlight 下载网页的解析,关于wp7 gb2312编码

    原文:windows phone 7,sliverlight 下载网页的解析,关于wp7 gb2312编码 关于silverlight和wp7(windows phone 7)是默认不支持gb2312 ...

  5. Java的URL来下载网页源码

    import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; impor ...

  6. http下载网页

    //http.c #include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ ...

  7. PHP下载网页

    <?php /*   author:whq   作用:获取网页的内容 */   include "../Snoopy/Snoopy.class.php";class Cute ...

  8. Java如何读取和下载网页?

    在Java编程中,如何读取和下载网页? 以下示例显示如何使用net.URL类的URL()构造函数来读取和下载网页. package com.yiibai; import java.io.Buffere ...

  9. 用firefox的插件下载网页中的视频

    对于网页中的一些视频,直接下载不了,可以用专用下载软件下载,也可以用firefox的NetVideohunter Video Downloader插件下载网页中的视频,方便快捷. 工具/原料   fi ...

随机推荐

  1. Java中常用的url签名防篡改方法

    实现方式:Md5(url+key) 的方式进行的. 1.key可以是任意的字符串,然后“客户端”和“服务器端”各自保留一份,千万不能外泄. 2.请求的URL 例如:  name=lxl&age ...

  2. CS代码代写, 程序代写, java代写, python代写, c/c++代写,csdaixie,daixie,作业代写,代写

    互联网一线工程师程序代写 微信联系 当天完成特色: 互联网一线工程师 24-48小时完成.用心代写/辅导/帮助客户CS作业. 客户反馈与评价 服务质量:保证honor code,代码原创.参考课程sl ...

  3. 浏览器中查看HTTP的头部文件

    本文以chrome浏览器为例,来讲解下在浏览器中,如何查看http的头部文件. 1.打开chrome浏览器,输入地址,如下图所示. 2.鼠标右击,在右键菜单中选择[检查],如下图所示. 3.选择“Ne ...

  4. Linux基础及系统优化

    1 如何实现自动挂载操作(光驱自动挂载--fstab) 1.1 方法 第一种方法:编辑fstab文件 vi /etc/fstab /dev/cdrom /mnt iso9660 default 0 0 ...

  5. 论文研读Unet++

    Unet++: A Nested U-Net Architecture for Medical Image Segmentation Unet++ 论文地址 这里仅进行简要介绍,可供读者熟悉其结构与特 ...

  6. 【JAVA】POI生成EXCEL图表(柱状图、折线等)

    1.使用excel工具自带的图形工具创建一个图: 2.绑定数据区域: 3.数据区域绑定完成,我们要做的就是将数据写入到数据区域中: 4.标记 5.POI 引入包 <!-- https://mvn ...

  7. PHP和javascript判断用户使用的是手机还是电脑

    PHP判断手机还是电脑 <?php $is_mobile = (is_mobile() == true) ? "手机" : "电脑"; echo '< ...

  8. Linux下编译PHP常见错误及解决方法

    1.configure: error: xml2-config not found. Please check your libxml2 installation.yum install libxml ...

  9. 西安7月21日「拥抱开源,又见.NET:壹周年Party」线下交流活动

    本次活动既是.NET西安社区的第四次线下交流活动,也是.NET西安社区成立一周年庆活动..NET西安社区2018年7月20日成立,经过一年时间的发展,社区共举办过3次大型线下交流活动,社区人数由最初的 ...

  10. HDU 6043:Colorful Tree(树上统计所有路径总颜色数)***

    题目链接 题意 给出一棵有n个结点的树,每个结点有一个颜色,问在这棵树的所有路径中,每条路径的颜色数求和是多少. 思路 求每种颜色的贡献可以转化为总的和减去每种颜色在哪些路径上没有出现的贡献,一个颜色 ...