requests库
- 了解requests库
- 熟练掌握requests库基本使用
- 熟悉使用代理,处理cookie等
get请求数据
import requests
headers = {'~~~~'}
url = '~~~'
kw = {'kw':'中国'}
resp = requests.get(url,headers=headers,params=(kw))
print(resp)
post发送请求
resp =request.post(url,data=data)
import requests
url = '~~~'
data = {'~~':'~~~'}
headers = {'~~':'~~~~'}
resp = requests.post(url,data=data,headers=headers)
print(resp.text)
proxies代理
import requests
url = '~~~'
proxy = {'http':'~~.~~.~~.~~:~~~~~'}
resp = requests.get(url,proxies=proxy)
print(resp.text)
处理cookie
import requests
url = '~~~~'
resp = requests.get(url)
print(resp.cookie)
print(resp.cookies.get_dict())
session共享cookie信息
import requests
post_url = '~~~'
post_data = {'username':'~~~~','password':'~~~~'}
headers = {'~~':'~~~~'}
#登陆
session = requests.session()
session.post(post_url,headers=headers,data=post_data)
#访问个人网页
url = '~~~'
resp = session.get(url)
print(resp.text)
处理不信任SSL证书,响应错误
verify=Flase
import requests
url = '~~~'
resp = requests.get(url,verify=False)
print(resp.content.decode('utf-8'))