w3resource

Python Web Scraping: Get the number of magnitude 4.5+ earthquakes detected worldwide by the USGS

Python Web Scraping: Exercise-25 with Solution

Write a Python program to get the number of magnitude 4.5+ earthquakes detected worldwide by the USGS.

Sample Solution:

Python Code:

#https://bit.ly/2lVhlLX
# landing page:
# http://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php
import csv
import requests
csvurl = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.csv'
rows = list(csv.DictReader(requests.get(csvurl).text.splitlines()))
print("The number of magnitude 4.5+ earthquakes detected worldwide by the USGS:", len(rows))
  
 

Sample Output:

The number of magnitude 4.5+ earthquakes detected worldwide by the USGS: 397

Flowchart:

Python Web Scraping Flowchart: Get the number of magnitude 4.5+ earthquakes detected worldwide by the USGS

Python Code Editor:

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

Previous: Write a Python program to get movie name, year and a brief summary of the top 10 random movies.
Next: Write a Python program to display the contains of different attributes like status_code, headers, url, history, encoding, reason, cookies, elapsed, request and content of a specified resource.

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-25.php