首页 > 编程语言 >python 网页登录了之后拿着cookie直接用于脚本程序获取api接口数据

python 网页登录了之后拿着cookie直接用于脚本程序获取api接口数据

时间:2022-10-28 17:14:25浏览次数:56  
标签:http python res urllib3 url api cookie print

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#python3.7 cookie urllib3,requests
#
#pip install requests
#分析网站数据源接口规律
#当前支持基于‘网页登录了之后拿着cookie直接用于脚本程序获取api接口数据
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


import urllib3  
import requests

HEADERS = {"cookie": 'JSESSIONID=0501AEF56FBF967A1A13F3E42688B877; sid=5af6074c-0e62-47c7-9a10-1f90335a8c40'}
#url = 'http://192.168.145.37:8090/vmBatchNoController/queryVmBatchNoList.do?order=asc&limit=20&offset=20&planKind=6&pdtcorpCode=-1&batchno=&creator=&_=1666941577426'
url = "http://192.168.145.37:8090/vmBatchNoController/queryVmBatchNoList.do?order=asc&limit=20&offset=40&planKind=6&pdtcorpCode=-1&batchno=&creator=&_=1666944167967"
#print()
#req = urllib3.request(url, headers=HEADERS)
#print(req)
#text = urllib3.urlopen(req).read()  
#print(text)


#http = urllib3.PoolManager()  # 线程池生成请求
#res = http.request('POST', url, fields={"Accept": "application/json, text/javascript, */*; q=0.01",
''''
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJkZXBhY29kZSI6IjM0IiwiZm9yY2UiOjAsInNpZCI6IjVhZjYwNzRjLTBlNjItNDdjNy05YTEwLTFmOTAzMzVhOGM0MCJ9.LPlQcXW53MbUpPexTXT7G1Fvn_BYpD3TtYQKeTraLhGCSsMdKukpTEGAVTQXin0wNGp4hjQRjztnqmzDcdtzuA",
"Connection": "keep-alive",
"Content-Type": "application/json",
"Cookie": "JSESSIONID=0501AEF56FBF967A1A13F3E42688B877; sid=5af6074c-0e62-47c7-9a10-1f90335a8c40",
"Host": "192.168.145.37:8090",
"Referer": "http://192.168.145.37:8090/vmBatchNoController/batchInfoPage.do",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"})
'''

#print(res.data.decode())

fils = {

    'JSESSIONID':'0501AEF56FBF967A1A13F3E42688B877-666',
    'sid':'adb05949-f607-4f5e-9ae8-f8da3f5974bf-xxx'
    }

r = requests.get(url,cookies=fils)
res = r.text
#print(res)
#print(type(res))
da01 = res.split(":[")[2]
#print(da01)
#筛出limit 20 json数据
da02 = da01.split("]")[0]
#print(da02)

 

标签:http,python,res,urllib3,url,api,cookie,print
From: https://www.cnblogs.com/ruiy/p/16836690.html

相关文章

  • python cmake 下载失败?   No CMAKE_C_COMPILER could be found.
    1.pipinstallcmake--default-timeout=100-ihttps://pypi.tuna.tsinghua.edu.cn/simple 2.第二个错误: --Buildingfor:VisualStudio162019  --Selectin......
  • C# webAPI +access+xadmin+layui 前端
    1.首先创建webAPI项目: 2.创建DAL类库,用户访问数据库。添加AccessHelper封装一个数据库访问类:usingSystem;usingSystem.Collections.Generic;usingSystem.Data;using......
  • 常用的Python函数有几类
    今天就给大家介绍12类,新手在做写代码的时候容易卡壳,尤其当接触的函数以及其他知识比较多的时候,经常会看完需求之后不知道自己该用什么方法来实现它,实现的逻辑可能你有,但怎么......
  • python lxml 解析
    1.lxml的安装 pipinstalllxml2.导入lxml的etree库fromlxmlimportetree 示例1fromlxmlimportetreehtml=etree.HTML(response.text)ret_list=htm......
  • python自学 简单的网站开发 2
    1.一般网站会有多个视图,我们要先在Views.py 中添加多个视图地址。defadd(request):returnHttpResponse("add....")deffind(request):returnHttpRespon......
  • ROS2时间同步(python)
    最近1周一直研究ROS2的时间同步,翻越很多博客,很少有人使用ROS2进行时间同步的代码,无奈不断尝试与源码阅读,终于将其搞定,为此,本博客将介绍基于python的ROS2的时间同步方法。......
  • Python 简易版贪食蛇(源代码)
    Python简易版贪食蛇简易版贪食蛇代码如下,直接运行即可。1.效果图2.源代码源代码如下:#!/usr/bin/envpython#-*-coding:utf-8-*-importpygameaspygameimp......
  • 使用python 绘制中国人口热气图
    使用pythonmatlib绘制热力图绘制世界地图点击查看代码importmatplotlib.pyplotaspltfrommpl_toolkits.basemapimportBasemapplt.figure(figsize=(16,8))m......
  • python-threading.Event()
    threading模块提供Event类实现线程之间的通信threading.Event可以使一个线程等待其他线程的通知。其内置了一个标志,初始值为False。线程通过wait()方法进入等待状态,直到另......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......