w3resource

Python Web Scraping: Get the number of people visiting a US government website right now

Python Web Scraping: Exercise-13 with Solution

Write a Python program to get the number of people visiting a U.S. government website right now.

Source: https://analytics.usa.gov/data/live/realtime.json

Sample Solution:

Python Code:

#https://bit.ly/2lVhlLX
# via: https://analytics.usa.gov/
import requests
url = 'https://analytics.usa.gov/data/live/realtime.json'
j = requests.get(url).json()
print("Number of people visiting a U.S. government website-")
print("Active Users Right Now:")
print(j['data'][0]['active_visitors'])
  
 

Sample Output:

Number of people visiting a U.S. government website-
Active Users Right Now:
103910

Flowchart:

Python Web Scraping Flowchart: Get the number of people visiting a U.S. government website right now.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to list all language names and number of related articles in the order they appear in wikipedia.org.
Next: Write a Python program get the number of security alerts issued by US-CERT in the current year.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/web-scraping/web-scraping-exercise-13.php