python3 urllib使用1
2015-08-04 23:34
603 查看
post方式
# -*- coding:utf-8 -*-
import urllib.parse #python2 在这道程序中只需引入urllib
import urllib.request #python 在这道程序中引入urllib2
values = {}
values['username']="借物少年"
values['password']="XXXXXXX"
data=urllib.parse.urlencode(values).encode(encoding='utf-8')
url="http://passport.cnblogs.com/user/signin?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F"
request1=urllib.request.Request(url,data)
response1=urllib.request.urlopen(request1)
print (response1.read())
Get方式
# -*- coding:utf-8 -*-
import urllib.parse #python2 在这道程序中只需引入urllib
import urllib.request #python 在这道程序中引入urllib2
values = {}
values['username']="借物少年"
values['password']="XXXXXXX"
data=urllib.parse.urlencode(values).encode(encoding='utf-8')
url="http://passport.cnblogs.com/user/signin?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F"
geturl1=url+"?"+str(data)
request1=urllib.request.Request(geturl1)
response1=urllib.request.urlopen(request1)
print (response1.read())
# -*- coding:utf-8 -*-
import urllib.parse #python2 在这道程序中只需引入urllib
import urllib.request #python 在这道程序中引入urllib2
values = {}
values['username']="借物少年"
values['password']="XXXXXXX"
data=urllib.parse.urlencode(values).encode(encoding='utf-8')
url="http://passport.cnblogs.com/user/signin?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F"
request1=urllib.request.Request(url,data)
response1=urllib.request.urlopen(request1)
print (response1.read())
Get方式
# -*- coding:utf-8 -*-
import urllib.parse #python2 在这道程序中只需引入urllib
import urllib.request #python 在这道程序中引入urllib2
values = {}
values['username']="借物少年"
values['password']="XXXXXXX"
data=urllib.parse.urlencode(values).encode(encoding='utf-8')
url="http://passport.cnblogs.com/user/signin?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F"
geturl1=url+"?"+str(data)
request1=urllib.request.Request(geturl1)
response1=urllib.request.urlopen(request1)
print (response1.read())
相关文章推荐
- [2015-08-04] python015
- 初窥Python(二)——修改pip源
- python 爬虫部分解释
- Python开发--pprint
- Python KNN 情感分类
- Python开发--os.path
- Python开发--fileinput
- Python开发--filecmp
- Python开发--tempfile
- Python开发--glob
- Python开发--linecache
- python开发--pickle
- 在python的应用程序中,不需要关系型数据库时,如MySQL可以使用python提供的持久字典dbm来存储名称和值(键值对)
- python中的shelve模块,可以提供一些简单的数据操作
- 4000 python中的zlib模块提供了压缩和解压缩的方法
- 函数参数一:传递与匹配规则
- 二阶切比雪夫多项式实现(scala版、python版)
- 理解python的with语句
- python 抓取知乎
- 八个工具看Python数据生态圈的最新趋势