Python爬虫:基础操作03(模拟登录 / 防盗链 / 信息解密)
写在前面
使用目的:模块化程序,用于新手快速上手
声明:请勿用于非法操作
程序片段及功能
1. 网页数据登录
1.模拟用户登录:采用session方法模拟用户登录
import requests
# 会话
session = requests.session()
data = {"loginName": "XXXXXXXXXXX", "password": "XXXXXXXX"}
# 1. 登录
url = "https://XXXXXXXXX/login"
resp = session.post(url, data=data)
resp.encoding = 'utf-8'
print(resp.text)
print(resp.cookies) # 看cookie
# 2. 获取数据
# 刚才的那个session中是有cookie的
resp = session.get(url )
print(resp.text)
resp = requests.get(url , headers={"Cookie":"XXXXXXXX"})
print(resp.text)
2.防盗链处理:网页访问时,有专门的监测程序识别是否是人为操作,防盗链就是其中的一种监测手段,查找方法见附件
3.信息解密:见附件
代码附件
- Python爬虫:基础操作03-1:Requests 登陆网站获取文本信息
- Python爬虫:基础操作03-2:Requests 防盗链(文件保存)
- Python爬虫:基础操作03-3:Requests+pycrypto 信息解密
- Python爬虫:基础操作03-4:Requests 验证码