Fundamentals 8 min read

How to Scrape and Visualize a Year of Global Earthquake Data with Python

This tutorial walks you through discovering a real‑time earthquake data source, analyzing its pagination API, building a Python scraper with requests, parsing the JSON responses, storing the results in CSV, and performing visual analyses such as top‑magnitude locations, monthly frequency, repeat‑site counts, magnitude distribution, and word‑cloud generation.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Scrape and Visualize a Year of Global Earthquake Data with Python

After seeing recent earthquake news in Guangzhou and Taiwan, the author decided to collect global earthquake data for the past year to identify high‑frequency zones.

Website Analysis

The chosen source is the China Earthquake Networks website ( http://news.ceic.ac.cn/index.html ), which provides real‑time global earthquake information, map visualizations, and historical queries.

By inspecting the pagination, the author discovered that each page of results is loaded via a JavaScript XHR request. The request URL follows a pattern where the page parameter controls the page number and a timestamp parameter (the trailing _ value) changes dynamically.

Scraper Implementation

The scraper follows three basic steps:

Send HTTP requests (using requests) with a proper User‑Agent and handle character encoding.

Parse the JSON response to extract the required fields.

Save the extracted data to a CSV file.

Sample code (simplified):

import requests, cchardet, csv, json
url = "http://www.ceic.ac.cn/ajax/speedsearch?num=6&&page=1&&callback=jQuery...&_={timestamp}"
headers = {"User-Agent": "Mozilla/5.0"}
resp = requests.get(url, headers=headers)
if resp.status_code == 200:
    data = json.loads(resp.text)
    # extract fields and write to CSV

By constructing URLs for all 59 pages (one per page of results) the full year’s data can be downloaded.

Data Visualization and Analysis

After saving the data, the author performed several analyses:

Top 10 locations with the highest magnitudes (e.g., Fiji Islands 8.1, northern Peru 7.8).

Monthly earthquake count comparison, revealing peaks in June (144 events) and August (143 events).

Frequency of repeated earthquakes at the same location, showing many repeats in Chinese provinces, especially Sichuan.

Distribution of earthquake magnitudes, with low‑magnitude events (around 3.0) dominating the dataset.

Word‑cloud generation of high‑frequency regions.

These visualizations demonstrate that the global earthquake activity is heavily concentrated in certain regions, with China appearing in nine of the top ten high‑frequency locations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Pythondata analysisCSVvisualizationEarthquake Data
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.