一、安装 requests 模块
pip install requests
Requests 中文文档
二、使用模块
import requests as req
''' 1、GET,POST的基本语法 '''
# GET请求
response = req.get(url,params,**kwargs)
# 例子:req.get(url,params={'wd':'百度'},headers=headers) # headers:字典
# POST请求
response = req.post(url,data,json,**kwargs)
# 例子:req.post(urlfy,data={'wd':'百度'},headers=headers) # headers:字典
''' 2、req.request 使用 '''
proxies={'http/https':'代理服务器地址'}
# headers 包含但不限于这些内容
headers={
'Referer': '访问此网页前一个页面',
'User-Agent': '计算机、浏览器信息',
'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Cookie':'Cookie信息',
'Content-Type': 'application/x-www-form-urlencoded',
}
req.request(
method='请求的模式',
url='url'