Search code examples
pythonjsonpython-requestsscreen-scraping

Scrape this value from a request response


unluckily i can provide only the output of the request and not the full code since it contains quite private infos, basically when printing the reuqest as text file i get a json one, something like that:

{"redirectUrl":"https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-....."}

How can i scrape that Paypal url? tried by doing this but it didn't worked:

content = checkout.text()
checkout.url = content["redirectUrl"]

I only get this error while doing it:

content = checkout.text() TypeError: 'str' object is not callable


Solution

  • Assuming you're using the requests library, you can simply do:

    resp = requests.get(url=url)
    content = resp.json()
    
    redirect_url = content["redirectUrl"]
    

    You can read more about the request content here, including the json request content.