python实操登录指定网站
分类专栏: Python
简介 python实操登录指定网站,供参考学习, 样式给广大开发者参考。
<pre class="ql-syntax" spellcheck="false">import requests
import re
import time
index_url = "http://account.chinaunix.net/login"
header = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Cookie": "Hm_lvt_0ee5e8cdc4d43389b3d1bfd76e83216b=1610677524; Hm_lpvt_0ee5e8cdc4d43389b3d1bfd76e83216b=1610677524; __pta=246804210.1610677525.1610677525.1610677525.1; __pts=582931432; __ptb=582931432; account_chinauni=accountchinauni; XSRF-TOKEN=hDgiUtrbWhkrDhdKhtsOgwRYomqqyUE6c9gCcyQA; laravel_session=APKvoIT7gV1FoUQ78zmqSCglMjjQbucPqcEbA7Sa; reg_referer=account.chinaunix.net; captcha_gee=6000fd4b74f20; st_user_token=849b8de97ba812e2a844d51cdb57e194",
"Host": "account.chinaunix.net",
"Pragma": "no-cache",
"Referer": "http://account.chinaunix.net/login/out",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
}
headers = {
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate",
"Accept-Language":"zh-CN,zh;q=0.9",
"Connection":"keep-alive",
"Host":"account.chinaunix.net",
"Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3610.2 Safari/537.36",
}
login_session = requests.session()
# 正则表达式,
token_search = re.compile(r'name="_token"\svalue="(.*?)"')
# 一定要使用login_session,否则无法保存cookie
index_response = login_session.get(url=index_url, headers=headers)
# print(index_response.text)
# 匹配文本中的token
token_value = re.search(token_search, index_response.text).group(1)
print(token_value)
# 开始构造登录数据
data = {
"username": "ab135790",
"password": "bomei123",
"_token": token_value,
"_t": int(time.time()) # 经过分析是时间戳
}
# 登录的时候使用的接口,使用的URL
login_url = 'http://account.chinaunix.net/login/login'
# 使用的是POST请求
login_response = login_session.post(url=login_url, headers=headers, data=data)
print(login_response.text)
# 再去请求设置页面的
phone_url = 'http://account.chinaunix.net/ucenter/user/index'
phone_response = login_session.get(url=phone_url, headers=headers)
# 是可以看到设置页面的手机号
print(phone_response.text)
</pre><p><br></p>
分享到:
转载:
喜欢 0
收藏
上一篇:
python实现登录它人站点
暂无评论信息
- 相关文章
- 文章推荐
-
眼镜试戴的装饰效果
开发眼镜类产品的时候需要使用试戴的功能,这里就有你需要的学习资料哦!
-
娱美德旗下MMORPG手游《传奇4》将推出新PVP玩法"比奇掠夺"&
《传奇4》推出新门派PVP玩法!韩国首尔2022年6月29日 /美通社/ -- 《传奇4》(MIR4)的新PVP玩法比奇掠夺(Bicheon Heist)于2022年6月28日推出。
-
docker搭建jenkins环境执行宿主机的docker无权限的解决方法
初次搭建jenkins持续集成工具的时候,在运行项目阶段出现 permission denied的情况
-
半导体短缺即将结束?分析师:如果没有 1 美元芯片会影响更多
德勤咨询(Deloitte Consulting)的芯片分析师认为,随着芯片行业资本支出的增加,需求度较高的工厂已经开工,预示着短缺情况即将结束。
- 点击排行
- 站长推荐
- 猜你喜欢
- 网站信息
- 站内问答:12篇
- 站内文章:212篇
- 建站时间:已运行1107天
- 备案号: 浙ICP备2022018799号
- 语言:
English(USA)
French(FR)
Chinese(ZH)
无数据