How to Scrape Qunar Tourist Spot Data and Visualize It with Baidu Maps & ECharts
This guide walks you through using Python to crawl Qunar’s tourist spot pages, retrieve location and sales data, enrich it with Baidu Map’s geocoding API, and then create interactive heatmaps and ranking charts with ECharts, while storing results in JSON and Excel files for further analysis.
This tutorial shows how to use Python to scrape Qunar’s tourist‑spot listings, extract each spot’s sales volume and address, convert the addresses to latitude/longitude via Baidu Map’s Geocoder API, and finally visualise the data with Baidu Maps heatmaps and ECharts ranking charts.
1. Prepare APIs and Tools
We use Baidu Map API for geographic visualisation and ECharts for charting. Both are free to use and widely adopted in web applications.
2. Determine Output Files
The scraped data will be saved as JSON files for the front‑end visualisation and as an Excel file (via pandas) for offline inspection.
3. Crawl Data
Steps:
Analyse the Qunar URL pattern, e.g.
http://piao.qunar.com/ticket/list.htm?keyword=PLACE&page=PAGE.
Iterate through pages, fetch each page with requests, and extract the required fields using xpath (preferred over regular expressions).
Extract the spot name, address, and sales number. Example extraction code:
import requests, lxml.etree as ET
url = "http://piao.qunar.com/ticket/list.htm?keyword=北京&page={}"
for i in range(1, 401):
html = requests.get(url.format(i)).text
tree = ET.HTML(html)
spots = tree.xpath('//div[@class="list_item"]')
for s in spots:
name = s.xpath('.//a[@class="name"]/text()')[0]
address = s.xpath('.//p[@class="address"]/text()')[0]
sales = s.xpath('.//span[@class="sale_num"]/text()')[0]
# store the data …4. Save to Local Files
Collected records are written to an Excel file with pandas.DataFrame.to_excel() and also dumped to a JSON file for later use.
5. Get Coordinates via Baidu Geocoder
For each address we call the Baidu Geocoder API:
import requests, json
api = "http://api.map.baidu.com/geocoder/v2/"
params = {"address": address, "output": "json", "ak": "YOUR_BAIDU_AK"}
resp = requests.get(api, params=params).json()
lng, lat = resp["result"]["location"]["lng"], resp["result"]["location"]["lat"]The latitude, longitude and the previously obtained sales number are combined into a JSON object of the form {"x": lng, "y": lat, "value": sales}.
6. Generate JSON for Map and Chart
Three JSON files are produced:
One for Baidu Map heatmap (array of {x, y, value}).
Two for ECharts – one for the heatmap layer and another for the ranking bar chart.
7. Render in Browser
We create a simple HTML page that loads the JSON files, initialises the Baidu Map, adds a HeatmapOverlay, and draws an ECharts bar chart. Because the page loads local files, it must be served by a local HTTP server, e.g.: python -m http.server 8000 Open http://127.0.0.1:8000/ and the heatmap and ranking chart appear.
Postscript
Using a free Baidu developer account (limited to 6 000 requests per day) we scraped the first 400 pages (≈4 500 spots) on 2017‑09‑10. The resulting visualisations show the most popular tourist destinations during the National Day holiday. The demo is available at easyinfo.online and the source code has been uploaded to GitHub.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
