| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
cookie 登录
import requests
# cookie 登录
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
'Cookie': 'Cookie值'
}
url = "http://xue.ujiuye.com/user/index/"
response = requests.get(url, headers=headers)
print(response.status_code, response.encoding)
print(response.url)
with open("./test.html", "w", encoding="utf-8") as f:
f.write(response.text)session 登录
import requests
session = requests.session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
}
login_url = "https://security.kaixin001.com/login/login_post.php"
data = {
"loginemail": "用户名",
"password": "密码",
}
response = session.post(login_url, data=data, headers=headers)
print(response.text)代理 (proxy server 实际上指代理服务器)
代理实例
import requests
proxies = {
"http": "http://121.31.12.12:5212",
"https": "https://222.22.11.21:3131",
}
response = requests.request("get", "http://www.baidu.com/", proxies=proxies)
print(response.text)使用 json 模块
将 Python 类型转换为 json 字符串类型: json.dumps()
json_data = json.dumps(dic)将 json 字符串类型转换为 Python 类型 (字典或列表): json.loads()
dic_data = json.loads(json_data)
Requests 方法
| Back | FazBrowse Home | New Git URL |