http协议

本文展示了如何使用Python的requests库进行GET和POST请求。在GET请求中,提取网页的图片链接;POST请求用于模拟用户登录,提交用户名和密码数据。
摘要由CSDN通过智能技术生成
'''提交
请求地址  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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

光明有我16620122910

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值