0

I am trying to extract the link I am getting from a curl command. Curl command throws back of type string.

{"success":true,"key":"Syv77d","link":"https://file.io/Syv77d","expiry":"14 days"}  

In my below code this gets https://file.io/Syv77d","expiry":"14 days"}
link = re.search('https://.*$',fileIO)

What I wanted was just https://file.io/Syv77d

The link would vary so i would need the url without the double-qoutes. I think I am missing something in my regex.

Dee
  • 401
  • 3
  • 9
  • 22
  • 3
    Use a JSON parser? Just get `json.loads(x)["link"]` where `x` is the JSON – ctwheels Feb 22 '18 at 15:45
  • 5
    It appears the response is in [JSON](https://json.org/) format. You may consider using Python's `json` module instead of manually parsing. – Cong Ma Feb 22 '18 at 15:45

1 Answers1

1

Convert the string object to a JSON object.

Ex:

import json
jData = json.loads('{"success":true,"key":"Syv77d","link":"https://file.io/Syv77d","expiry":"14 days"}')
jData["link"]
Rakesh
  • 81,458
  • 17
  • 76
  • 113