如何从初始URL python构造URL

时间:2016-10-20 03:48:54

标签: python

我正在尝试根据从初始网址获得的内容构建网址。

示例:

URL1:

http://some-url/rest/ids?configuration_path=project/Main/10-deploy

此处的回复是 123

URL2:

http://abc-bld/download/{RESPONSE_FROM_URL1_HERE}.latest_successful/artifacts/build-info.props

所以我的最终网址是:

http://tke-bld/download/123.latest_successful/artifacts/build-info.props

这里的回复是 Some.Text.here.123

然后我想抓住'Some.Text.here.123'并将其存储在一个变量中。

如何使用python完成此操作?

非常感谢任何帮助。感谢

2 个答案:

答案 0 :(得分:1)

您可以通过requests和一些字符串格式来实现,这些内容如下:

import requests

initial_url = "http://some-url/rest/ids"
initial_url_params = {
    "configuration_path": "project/Main/10-deploy"
}
with requests.Session() as session:
     response = session.get(initial_url, params=initial_url_params)

     second_url = "http://abc-bld/download/{0}.latest_successful/artifacts/build-info.props".format(response.content)

     response = session.get(second_url)
     print(response.content)

答案 1 :(得分:1)

假设您正在执行简单的HTTP GET请求,您可以使用requests

这样的东西
select * from 
(
select  transid,transno,transdate,transtype,
Row_number()over(partition by transno order by transdate desc) as rn
from trans
) where RN = 1