python操作requests

import requests
# POST http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=ZsZUlUILQjqxGLkopRAdEsyPBmdcjONCWRZXfEuuKawHzjKkBz HTTP/1.1
url='http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=ZsZUlUILQjqxGLkopRAdEsyPBmdcjONCWRZXfEuuKawHzjKkBz'
data={
    'ajax'	:1,
    'email'	:'admin',
    'user_pwd'	:'cGdWWURWa0RGemlYRm1rcm5icnlJVlVDeXdDcHFaTXRMb0dERUhZSndleGpxSmRBYWYlMjV1NjVCOSUyNXU3RUY0YWRtaW4lMjV1OEY2RiUyNXU0RUY2'

}
header={
    'Host':'106.52.182.140',
    # 'Connection':'keep-alive',
    # 'Accept':'application/json, text/javascript, */*; q=0.01',
    'X-Requested-With':'XMLHttpRequest',
    'Origin':'http://106.52.182.140',
    'Referer': 'http://106.52.182.140/fanwe/index.php?ctl=user&act=login'
# Accept-Encoding: gzip, deflate
# Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
# Cookie: PHPSESSID=u2ckdisnqqhk958i43qftucuf4
}
#发起post请求
rq = requests.post(url=url,data=data,headers=header)
# print(rq.text)
hd = rq.headers  #获取响应头信息
print(hd)
#获取响应头信息里面的set-cookie信息
set_cookie = hd['Set-Cookie']
print(set_cookie)
#set-cookie的值拆分,获取PHPSESSID
cookie=set_cookie.split(';',1)[0]
print(cookie)



#编辑个人资料
url2 ='http://106.52.182.140/fanwe/member.php?ctl=uc_account&act=save'
#请求数据
data2={
    'address':'中国北京市宜章李田龙溪村一组',
    'avatar_file':'',
    'city_id':'52',
    'commit':'保存更改',
    'graduation':'本科',
    'marriage':'未婚',
    'phone'	:'0735-17674124567',
    'province_id':'2',
    'university':'北京大学'
}
#请请求头
header2 = {
        'Host': '106.52.182.140',
        'Connection':'keep-alive',
        'Content-Length': '361',
        'Cache-Control':'max-age=0',
        'Upgrade-Insecure-Requests': '1',
        'Origin':'http://106.52.182.140',
        'Content-Type':'application/x-www-form-urlencoded',
        'Referer':'http://106.52.182.140/fanwe/member.php?ctl=uc_account',
        'Cookie':cookie
}
rq = requests.post(url=url2,headers=header2,data=data2)
print(rq.text[315:345])
python操作requests
做接口自动化一般使用到request是模块,python有很强大的模块

```python
import requests
# POST http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=ZsZUlUILQjqxGLkopRAdEsyPBmdcjONCWRZXfEuuKawHzjKkBz HTTP/1.1
url='http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=ZsZUlUILQjqxGLkopRAdEsyPBmdcjONCWRZXfEuuKawHzjKkBz'
data={
    'ajax'	:1,
    'email'	:'admin',
    'user_pwd'	:'cGdWWURWa0RGemlYRm1rcm5icnlJVlVDeXdDcHFaTXRMb0dERUhZSndleGpxSmRBYWYlMjV1NjVCOSUyNXU3RUY0YWRtaW4lMjV1OEY2RiUyNXU0RUY2'

}
header={
    'Host':'106.52.182.140',
    # 'Connection':'keep-alive',
    # 'Accept':'application/json, text/javascript, */*; q=0.01',
    'X-Requested-With':'XMLHttpRequest',
    'Origin':'http://106.52.182.140',
    'Referer': 'http://106.52.182.140/fanwe/index.php?ctl=user&act=login'
# Accept-Encoding: gzip, deflate
# Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
# Cookie: PHPSESSID=u2ckdisnqqhk958i43qftucuf4
}
#发起post请求
rq = requests.post(url=url,data=data,headers=header)
# print(rq.text)
hd = rq.headers  #获取响应头信息
print(hd)
#获取响应头信息里面的set-cookie信息
set_cookie = hd['Set-Cookie']
print(set_cookie)
#set-cookie的值拆分,获取PHPSESSID
cookie=set_cookie.split(';',1)[0]
print(cookie)



#编辑个人资料
url3 ='http://106.52.182.140/fanwe/member.php?ctl=uc_account&act=save'
#请求数据
data2={
    'address':'中国上海宜章李田龙溪村一组',
    'avatar_file':'',
    'city_id':'52',
    'commit':'保存更改',
    'graduation':'高中',
    'marriage':'已婚',
    'phone'	:'0735-17864124567',
    'province_id':'2',
    'university':'清华大学'
}
#请请求头
header2 = {
        'Host': '106.52.182.140',
        'Connection':'keep-alive',
        'Content-Length': '361',
        'Cache-Control':'max-age=0',
        'Upgrade-Insecure-Requests': '1',
        'Origin':'http://106.52.182.140',
        'Content-Type':'application/x-www-form-urlencoded',
        'Referer':'http://106.52.182.140/fanwe/member.php?ctl=uc_account',
        'Cookie':cookie
}
rq = requests.post(url=url3,headers=header2,data=data2)
print(rq.text[315:345])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值