重新认识urllib
# coding=utf-8
# urllib_get_file=urllib.request.urlretrieve(url=None,filename="test.zip")
# basic usage of urllib
from urllib import request
url = "https://www.cnblogs.com/SunshineKimi/"
msg = request.Request(url)
# msg.add_header("1",2)
# msg.set_proxy()
rep = request.urlopen(msg)
print(rep.read()) # how to use proxy to request in urllib
proxies = {"http": "user:passwd@ip:port"} # buy proxy
proxy = {"http": "111.79.44.217:9999"} # free proxy
proxy_handler = request.ProxyHandler(proxy) # there also exist HttpHandler() basic handler
opener = request.build_opener(proxy_handler)
response = opener.open(url, data=None)
print(response.headers) # auth by proxy
passwd_manager=request.HTTPPasswordMgrWithDefaultRealm()
passwd_manager.add_password(realm=None,uri=proxy,user="user",passwd="password")
buy_auth_handler=request.ProxyBasicAuthHandler(passwd_manager)
opener_auth=request.build_opener(buy_auth_handler)
response_auth=opener_auth.open(url=None,data=None).read()
print(response_auth)
重新认识urllib的更多相关文章
- python urllib
在伴随学习爬虫的过程中学习了解的一些基础库和方法总结扩展 1. urllib 在urllib.request module中定义下面的一些方法 urllib.request.urlopen(url,d ...
- Python3使用urllib访问网页
介绍 改教程翻译自python官网的一篇文档. urllib.request是一个用于访问URL(统一资源定位符)的Python模块.它以urlopen函数的形式提供了一个非常简单的接口,可以访问使用 ...
- 爬虫初探(1)之urllib.request
-----------我是小白------------ urllib.request是python3自带的库(python3.x版本特有),我们用它来请求网页,并获取网页源码. # 导入使用库 imp ...
- python 3.x urllib学习
urllib.request import urllib.request as ur url='http://ie.icoa.cn' user_agent = 'Mozilla/4.0 (compat ...
- Python爬虫学习(1): urllib的使用
1.urllib.urlopen 打开一个url的方法,返回一个文件对象,然后可以进行类似文件对象的操作 In [1]: import urllibIn [2]: file = urllib.urlo ...
- python2 与 python3 urllib的互相对应关系
urllib Python2 name Python3 nameurllib.urlopen() Deprecated. See urllib.request.urlopen() which mirr ...
- urllib+BeautifulSoup无登录模式爬取豆瓣电影Top250
对于简单的爬虫任务,尤其对于初学者,urllib+BeautifulSoup足以满足大部分的任务. 1.urllib是Python3自带的库,不需要安装,但是BeautifulSoup却是需要安装的. ...
- 初学python之urllib
urllib.request urlopen()urllib.urlopen(url, data, proxies) :创建一个表示远程url的类文件对象,然后像本地文件一样操作这个类文件对象来获取远 ...
- urllib.urlretrieve的用法
urllib.urlretrieve(url, local, cbk) urllib.urlretrieve(p,'photo/%s.jpg'%p.split('/')[-4]) url要下载的网站 ...
- 关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法
#encoding:UTF-8 import urllib.request url = "http://www.baidu.com" data = urllib.request.u ...
随机推荐
- The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.
在eclipse里运行jsp文件最初迟迟没有反应,重启报了这个错误,tomcat的端口设置有问题.需要打开服务器设置一下端口号. 点击Servers,如果没有这一项,按照Window-Show Vie ...
- 聊聊spring之贯穿全局的重要对象BeanDefinition
BeanDefinition 在 spring 中贯穿始终,spring 要根据 BeanDefinition 对象来实 例化 bean,只要把解析的标签,扫描的注解类封装成 BeanDefiniti ...
- SSM使用AbstractRoutingDataSource后究竟如何解决跨库事务
Setting: 绑定三个数据源(XA规范),将三个实例绑定到AbStractoutingDataSource的实例MultiDataSource(自定义的)对象中,mybatis SqlSessi ...
- SQL server 游标用法
declare @EmpCode varchar(50), @EmpName varchar(50), @EmpAddress varchar(200);declare curEmployee cur ...
- export default和export的使用方法
Node中 向外暴露成员,使用module.exports和exports module.exports = {} Node中导入模块 var 名称 = require('模块标识符') 在ES6中 ...
- Tunnel Warfare HDU - 1540
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- AI 数学基础 张量 范数
1.张量 几何代数中定义的张量是基于向量和矩阵的推广,通俗一点理解的话,我们可以将标量视为零阶张量,矢量视为一阶张量,那么矩阵就是二阶张量. 例如,可以将任意一张彩色图片表示成一个三阶张量,三个维度分 ...
- 聊聊SNMP协议
注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 本文源链接:https://www.cnblogs.com/chloneda/p/snmp-protoco ...
- C#简单的LogHelper
适用于不想使用log4net等第三方的Log工具的LogHelper.正规的还是要使用<C# 工具类LogHelper>的这种做法. using System; using System. ...
- 解决问题:当redis服务端断开的时候`进程会崩溃(转载6哥笔记)
package main import ( "fmt" "github.com/astaxie/beego/logs" "github.com/gar ...