Python实战一:获取某云app登录cookie

今天下午抽时间了解了python爬虫,简单认识了request库

需求:

因为天天需要登录某云app,帮别人签到,所以想写个python脚本来帮忙。

了解request库

request库是一个用于发送HTTP请求的库,可以用于向服务器发送GET、POST、PUT、DELETE等请求,并接收服务器返回的响应。

request库的基本用法如下:

  1. 安装request库:在命令行中执行pip install requests命令即可安装。

  2. 导入request库:在Python脚本中使用import requests语句将request库导入到当前脚本中。

  3. 发送GET请求:使用requests.get(url)函数发送GET请求,其中url为要访问的URL地址。例如:

import requests

# 发送GET请求
response = requests.get('https://www.example.com')
  1. 发送POST请求:使用requests.post(url, data)函数发送POST请求,其中url为要访问的URL地址,data为POST请求的参数。例如:
import requests

# 发送POST请求
data = {'username': 'admin', 'password': '123456'}
response = requests.post('https://www.example.com/login', data=data)
  1. 获取响应内容:使用response.text属性可以获取响应的内容,使用response.json()方法可以将响应内容解析为JSON格式的数据。例如:
import requests

# 发送GET请求并获取响应内容
response = requests.get('https://www.example.com')
content = response.text
json_data = response.json()
  1. 处理错误和异常:当访问URL出现错误时,可以使用response.status_code属性获取错误码,使用response.raise_for_status()方法抛出异常。例如:
import requests

# 发送GET请求并检查错误
response = requests.get('https://www.example.com')
if response.status_code == 200:
    # 请求成功,处理响应内容
    content = response.text
else:
    # 请求失败,抛出异常
    response.raise_for_status()

这只是request库的基本用法,还有许多高级功能和选项可以用来处理不同的HTTP请求和响应。详细的文档可以参考官方网站:https://requests.readthedocs.io/

代码实现:

import requests

# 构建请求头部信息
headers = {
    "Host": "api.xixunyun.com",
    "content-type": "application/x-www-form-urlencoded",
    "accept-encoding": "gzip",
    "user-agent": "okhttp/3.8.1"
}

# 构建请求参数
data = {
    "app_version": "4.9.6",
    "registration_id": "",
    "uuid": "自己的",
    "request_source": "3",
    "platform": "2",
    "mac": "",
    "password": "自己的",
    "system": "13",
    "school_id": "184",
    "model": "自己的",
    "app_id": "cn.vanber.xixunyun.saas",
    "account": "自己的账号",
    "key": ""
}

# 构建请求URL
url = "https://api.xixunyun.com/login/api?from=app&version=4.9.6&platform=android&entrance_year=0&graduate_year=0&school_id=自己的学校名 h2"

# 发起POST请求
response = requests.post(url, headers=headers, data=data)

# 打印响应内容
print(response.text)

  • 22
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip 基于Python的入门教程实战篇:网站+iOS App源码.zip

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

分才

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

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

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

打赏作者

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

抵扣说明:

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

余额充值