This question already has answers here:
Why can't Python parse this JSON data? [closed]
(3 answers)
Closed 5 years ago.
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.
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"]
Related
This question already has answers here:
What does the 'b' character do in front of a string literal?
(11 answers)
Convert a bytes array into JSON format
(8 answers)
Closed 2 years ago.
new to python here. Been trying this for quite a while now; would really appreciate some help.
I thought to try my hand at pulling data from an api, and what i got is a very long dictionary ( or at least i think its an dictionary )
response = requests.get('https://api.coingecko.com/api/v3/finance_products')
print(response.content)
can anyone give me any pointers on how to manipulate the results ?
I can't call the dictionary.
First few characters of it :
b'[{"platform":"Binance Savings","identifier":"CCOCOS30DAYSS001","supply_rate_percentage":"6.0","borrow_rate_percentage":null,"number_duration":null,"length_duration":null,"start_at":0,"end_at":0,"value_at":0,"redeem_at":0},{"platform":"DDEX Lending","identifier": etc etc
i'm not sure why there is a b' at the front.
Sorry if this isn't a clear question.
You can use
response.json()
which decodes it immediatly to a json object. Documentation here
This question already has answers here:
Extract email sub-strings from large document
(14 answers)
Closed 3 years ago.
Do you guys know how I'll be able to extract an email from a string using find()
info = "message email#gmail.com"
I want to be able to get the entire "email#gmail.com" and output only that to the screen.
You can do this by using regex:
import re
emails_list = re.findall('\S+#\S+', info)
This question already has answers here:
What's the u prefix in a Python string?
(5 answers)
Closed 6 years ago.
I am trying to parse the 'Meghan' part from the line:
link = http://python-data.dr-chuck.net/known_by_Meghan.html
...with the following regex:
print re.findall('by_(\S+).html$',link)
I am getting the output:
[u'Meghan']
Why I am getting the 'u'?
It means unicode. Depending on what you'll do with it, you can ignore it for the most part, of you can convert it to ascii by doing .encode('ascii')
This question already has answers here:
How to get URL of current page, including parameters, in a template?
(7 answers)
Closed 7 years ago.
I am writing a Django application. In my 'urls.py' I have written a URL pattern like this:
url(r'^rest/post/(.*)/$', rest_post),
Now when I am passing some URL like:
http://www.google.com/a?b
In my rest_post view I am getting only: http://www.google.com/a
I want to get the full URL. How do I do it?
simply
request.get_full_path()
in your views.
see https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.get_full_path
This question already has answers here:
urllib.quote() throws KeyError
(3 answers)
Closed 7 years ago.
I am trying to make a program that requests to steam to get a the cheapest price for an item. For this I will be using StatTrak™ P250 | Supernova (Factory New) as an example.
The problem is that when requesting, you will make a url:
http://www.steamcommunity.com/market/priceoverview/?country=SG¤cy=13&appid=730&market_hash_name=StatTrak™%20P250%20%7C%20Supernova%20%28Factory%20New%29
Afterwards, (I am using the requests module) I do this:
url = "http://www.steamcommunity.com/market/priceoverview/?country=SG¤cy=13&appid=730&market_hash_name=StatTrak™%20P250%20%7C%20Supernova%20%28Factory%20New%29"
requests.get(url)
However, the server will return an error.
I can't seem to find solutions to replace ™. I have tried %2122. In python I tried using u'\u084a' but that didn't work too. The problem is that python sends literally \u084a in the request. Is there any way to solve this?
Just use URL encoding. You can't use unicode in urls.
>>> import urllib
>>> f = {'market_hash_name': 'StatTrak™'}
>>> urllib.urlencode(f)
'market_hash_name=StatTrak%E2%84%A2'
Also possible
>>> urllib.quote_plus('StatTrak™')