requests库的小技巧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#coding:utf-8
import requests
 
 
# url = 'http://www.baidu.com'
# response = requests.get(url)
# print (response.cookies)
# print (type(response.cookies))
 
# 将cookjar转换成字典格式的cookies
 
# dict_cookies = requests.utils.dict_from_cookiejar(response.cookies)
# print (dict_cookies)
# print (type(dict_cookies))
 
# jar_cookies = requests.utils.cookiejar_from_dict(dict_cookies)
# print (jar_cookies)
# print (type(jar_cookies))
 
######################################关闭ssl认证
# CA认证是老外搞得,我们自己有一套,但是老外不承认,我们请求时就关闭ca认证,verify=False
# url = 'https://www.12306.cn/mormhweb/'
# try:
#     response = requests.get(url)
# except:
#     response = requests.get(url, verify=False)
# print (response.content)
 
 
######################################超时
# url = 'http://www.youtube.com'
#
# response = requests.get(url, timeout=3)<br><br># 断言<br># 判断语句是否为真:为真,过;不为真,抛出异常<br># assert response.status_code == 200

  

posted @   安迪9468  阅读(117)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示