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
You can do it via requests
and some string formatting , something along these lines:
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)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.