会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
道高一尺
博客园
首页
新随笔
联系
管理
订阅
上一页
1
···
20
21
22
23
24
25
26
27
28
···
47
下一页
2017年5月12日
requests-所有异常归类
摘要: 异常官方文档:http://www.python-requests.org/en/master/_modules/requests/exceptions/#RequestException
阅读全文
posted @ 2017-05-12 09:45 道高一尺
阅读(3792)
评论(0)
推荐(0)
2017年5月11日
requests-认证设置
摘要: 1 #如果需要用户名和密码才能登陆网站,则需要认证设置auth=() 2 import requests 3 response = requests.get(url,auth=('user','password')) 4 5 #或者 6 from requests.auth import HTTPBasicAuth 7 response = requests.get(url,auth=HTTP...
阅读全文
posted @ 2017-05-11 23:33 道高一尺
阅读(461)
评论(0)
推荐(0)
requests-代理设置
摘要: 1 import requests 2 3 proxies={ 4 'http':'http://192.168.1.1:88' 5 'https':'https://192.168.1.1:88' 6 #如果代理ip需要用户名和密码的话 'http':'user:password@192.168.1.1:88' 7 } 8 response = request...
阅读全文
posted @ 2017-05-11 23:25 道高一尺
阅读(1474)
评论(0)
推荐(0)
requests-证书验证
摘要: 1 import requests 2 #response = requests.get('https://www.12306.cn') 3 #print(response.status_code) 4 #以上会显示错误,因为需要证书验证 5 6 #解决证书问题,我们有两种方法 7 8 #方法一,我们可以通过设置verify=False来忽略证书验证 9 response ...
阅读全文
posted @ 2017-05-11 23:11 道高一尺
阅读(2669)
评论(0)
推荐(1)
requests-模拟登陆
摘要: 1 import requests 2 requests.get('http://httpbin.org/cookies/set/number/123456') 3 response = requests.get('http://httpbin.org/cookies') 4 print(response.text) 5 #以上结果为空,原来设想通过第一步的设置cookies,然后通过...
阅读全文
posted @ 2017-05-11 22:52 道高一尺
阅读(263)
评论(0)
推荐(0)
requests-文件上传
摘要: 1 import requests 2 files = {'file':open('D://tomas.jpg','rb')}#设定一个files,打开文件对象 3 response = requests.post('http://httpbin.org/post',files=files) 4 print(response.text)
阅读全文
posted @ 2017-05-11 22:29 道高一尺
阅读(307)
评论(0)
推荐(0)
requests-post请求
摘要: post与get方法的区别在于post需要提交一些数据以备处理。 在requests里面非常简单,headers,data都是直接加进去就可以了
阅读全文
posted @ 2017-05-11 21:20 道高一尺
阅读(252)
评论(0)
推荐(0)
requests-get请求
摘要: 1 import requests 2 3 response= requests.get('http://www.baidu.com')#get方法请求网址 4 print(response) 5 print(response.status_code)#状态码 6 print(response.text)#响应体 7 print(response.cookies)#获取cookies另外还有r...
阅读全文
posted @ 2017-05-11 20:37 道高一尺
阅读(427)
评论(1)
推荐(0)
urllib.parse
摘要: 1 url分解 import urllib.parse 2 3 result = urllib.parse.urlparse('http://www.baidu.com') 4 print(result) 5 结果为:ParseResult(scheme='http', netloc='www.baidu.com', path='', params='', query='', fragment...
阅读全文
posted @ 2017-05-11 18:53 道高一尺
阅读(2366)
评论(0)
推荐(0)
urllib.error
摘要: 1 #捕获异常 2 import urllib.request 3 import urllib.error 4 5 try: 6 response = urllib.request.urlopen('http://sasd.com') 7 except urllib.error.URLError as e: 8 print('挂掉的情形是:',e.reason) 1 ...
阅读全文
posted @ 2017-05-11 18:12 道高一尺
阅读(272)
评论(0)
推荐(0)
上一页
1
···
20
21
22
23
24
25
26
27
28
···
47
下一页
公告