-1

I'm trying to scrape a page with this JSON data:

{"supply": 33391639424594933, "circulation": 34239675266895397, "delegations": 1190828, "stake": 24567963450666814, "d": 0, "k": 500, "ADABTC": 2.669e-05, "ADAUSD": 1.17, "ADAEUR": 1.066, "ADAJPY": 143.18, "ADAGBP": 0.88944, "ADACAD": 1.47, "ADAAUD": 1.56, "ADABRL": 5.65, "tokens": 4012794, "policies": 49730, "load_24h": 0.7224179343311306, "load_1h": 0.8698008795204403, "load_5m": 0.923056640625}

All I want is to get the "tokens" value.

Here is my current script:

from bs4 import BeautifulSoup
import requests
import json

url = "https://pool.pm/total.json"
print(url)
page =requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
script = soup.find('tokens')

print(script)

But nothing happens when I run this code.

1

2 Answers 2

2

bs4 can parse HTML pages, not JSON. So you don't need bs4 here but requests:

import requests

r = requests.get('https://pool.pm/total.json')

print(r.json()['tokens'])
Sign up to request clarification or add additional context in comments.

Comments

0

This will work:

from bs4 import BeautifulSoup
import requests
import json

url = "https://pool.pm/total.json"
print(url)
page =requests.get(url)

script = page.json()['tokens']

print(script)

You don't need bs4 for json.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.