I am trying to get all the websites from this json file
Unfortunately, when I use this code:
JavaScript
x
8
1
import requests
2
3
response = requests.get("https://github.com/solana-labs/token-list/blob/main/src/tokens/solana.tokenlist.json")
4
output = response.json()
5
6
# Extract specific node content.
7
print(output['website'])
8
I get following error:
JavaScript
1
20
20
1
Traceback (most recent call last):
2
File "/Users/dusandev/Desktop/StreamFlowWebTests/extract.py", line 5, in <module>
3
output = response.json()
4
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
5
packages/requests/models.py", line 900, in json
6
return complexjson.loads(self.text, **kwargs)
7
File
8
"/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py",
9
line 346, in loads
10
return _default_decoder.decode(s)
11
File
12
"/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py",
13
line 337, in decode
14
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
15
File
16
"/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py",
17
line 355, in raw_decode
18
raise JSONDecodeError("Expecting value", s, err.value) from None
19
json.decoder.JSONDecodeError: Expecting value: line 7 column 1 (char 6)
20
Any help is appreciated. Thank you in advance
Advertisement
Answer
Use raw
data to get raw json
and then iterate over ‘tokens
‘ attr
of the response
object:
JavaScript
1
10
10
1
import requests
2
3
response = requests.get(
4
"https://raw.githubusercontent.com/solana-labs/token-list/main/src/tokens/solana.tokenlist.json")
5
6
output = response.json()
7
for i in output['tokens']:
8
if i.get('extensions'):
9
print(i.get('extensions').get('website'))
10