arabian_albert arabian_albert - 1 month ago 6
Python Question

How to construct URL from an initial URL python

I'm trying to construct a URL based on what I get from a initial URL.

Example:

URL1:

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


Response here is 123

URL2:

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


so my final URL will be:

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


Response here is Some.Text.here.123

Then I'd like to grab 'Some.Text.here.123' and store it in a variable.

How can I accomplish this with python?

Any help would be much appreciated. Thanks

Answer

Assuming that you are doing simple HTTP GET requests, you can use the requests library

Something like

import requests
initial_request = requests.get('http://request1.com/something')
value = request1.text

second_request = requests.get('http://request2.com/value={0}'.format(value))
response = second_request.text
Comments