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?



Follow us on Facebook and Twitter for latest update.