'''提交
请求地址 get/post
提交数据 post
提交cookies get/post
提交协议头headers get/post
'''
'''
响应格式
HTTP/1.1 200 OK
Set-Cookie: acw_tc=276082a4167327222312
'''
import re
'''
请求格式
1.get
请求方式GET
地址:url string
cookies dict
headers:User-Agent: Mozilla/5.0... dict
2.post
+data dict
'''
# get
import requests
url = "http://www.nspirit.cn/"
cookies = {"PSTM": "1601902139"}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"}
r = requests.get(url=url,
# headers=headers,
# cookies=cookies
)
if r.status_code == 200:
print(r.encoding)
print(r.apparent_encoding)
r.encoding = 'utf-8'
print(r.text)
match = re.findall('(http.*?)"', r.text)
if match:
ls = [i for i in match if i[-3:] in ("png", "jpg", "bmp")]
print(ls)
url = "https://www.zuhaowan.com/SoftV1/Login/getUserLogin?reqtime=" + str(round(time.time() * 1000))
data = {"userName": "张三", "userType": 0, "pwd": "123456789"}
print(url)
r = requests.post(url=url,
headers=headers,
cookies=cookies,
data=data)
if r.status_code == 200:
print(r.text)
http协议
最新推荐文章于 2024-10-07 01:36:35 发布
本文展示了如何使用Python的requests库进行GET和POST请求。在GET请求中,提取网页的图片链接;POST请求用于模拟用户登录,提交用户名和密码数据。
摘要由CSDN通过智能技术生成