Python程序读取URL

2024-04-19 22:03:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一个python程序将运行的网址。很简单,它只需要使用提供的凭据运行从应用程序生成的URL即可访问应用程序。我将安排每晚运行python脚本。你知道吗

我有一个生成URL的应用程序。如果我运行这个URL,它将生成JSON文件。你知道吗

我试图预缓存应用程序的输出,所以我想每天早上运行的网址。你知道吗

信息如下:

USERNAME = "test"
PASSWORD = "test5"
HOST = 'appl.xyz.net' 
PORT = 8080

示例URL为: http://appl.xyz.net:8080/app/content/pq/doQuery?solution=nd&path=&file=Test.nd&dataAccessId=1&paramid=4221

JSON码:

{
   "queryInfo":{
      "totalRows":"3"
   },
   "resultset":[
      [
         4215,
         null,
         "AAA"
      ],
      [
         4215,
         null,
         "BBB"
      ]
   ],
   "metadata":[
      {
         "colIndex":0,
         "colType":"Numeric",
         "colName":"id"
      },
      {
         "colIndex":1,
         "colType":"String",
         "colName":"Name"
      },
      {
         "colIndex":2,
         "colType":"String",
         "colName":"City"
      }
   ]
}

谢谢


Tags: 程序脚本json应用程序urlstringnetnull
1条回答
网友
1楼 · 发布于 2024-04-19 22:03:02

使用^{}库。你知道吗

那么你需要做的就是:

import requests

url = 'http://appl.xyz.net:8080/app/content/pq/doQuery?solution=nd&path=&file=Test.nd&dataAccessId=1&paramid=4221'
user = 'test'
password = 'test5'

# Takes care of the HTTP authentication
data = requests.get(url, auth=(user, password))
json_data = data.json()

StvnW在注释中提供了到CURL alternative in Python的链接,如果您不希望安装任何其他库。你知道吗

相关问题 更多 >