需自行下载与浏览器匹配的 Chromedriver,README 未说明版本对应关系;Python 必须 >= 3.9;URL 必须是从地点评论数入口生成的评论页链接,否则无法抓取;monitor.py 需额外安装并运行 MongoDB。
conda create --name scraping python=3.9 --file requirements.txt
python scraper.py --N 50README 未说明显存或 GPU 要求;需要本地安装 ChromeDriver 驱动浏览器运行,监控功能需本地安装 MongoDB。
从 Google Maps 地点链接抓取最新评论并导出 CSV 的 Python 爬虫
用 Python 抓取 Google Maps 上商户的评论数据,适合做口碑分析和竞品调研时批量采集评论。
核心能力
- 按 POI 评论页 URL 抓取最新评论并输出 CSV
- 用 --N 控制抓取条数,默认取最近 100 条
- 支持按最新、最相关、评分高低排序评论
- monitor.py 配合 MongoDB 增量抓取并突破条数限制
- 可切换抓取 POI 元数据而非评论
容易踩的坑
- v1.1.0最新正式版2023-03-25 · 2023-03-25 00:16 UTC
Two major improvements:
- Place metadata scraping has been updated to obtain more information
- Defined a first version of place url search by keywords and coordinates
What's Changed
- Add WebDriver Management to download Chrome by @Matheus-Ribeiro-ITA in https://github.com/gaspa93/googlemaps-scraper/pull/25
- Bump numpy from 1.17.2 to 1.22.0 by @dependabot in https://github.com/gaspa93/googlemaps-scraper/pull/32
- change div class based on gmaps in june 2022 by @astrawnuts in https://github.com/gaspa93/googlemaps-scraper/pull/31
- Bump certifi from 2022.6.15 to 2022.12.7 by @dependabot in https://github.com/gaspa93/googlemaps-scraper/pull/33
- fix the order of
time.sleepandself.__scrollby @saito828koki in https://github.com/gaspa93/googlemaps-scraper/pull/38 - Search by coord by @gaspa93 in https://github.com/gaspa93/googlemaps-scraper/pull/40
New Contributors
- @Matheus-Ribeiro-ITA made their first contribution in https://github.com/gaspa93/googlemaps-scraper/pull/25
- @dependabot made their first contribution in https://github.com/gaspa93/googlemaps-scraper/pull/32
- @astrawnuts made their first contribution in https://github.com/gaspa93/googlemaps-scraper/pull/31
- @saito828koki made their first contribution in https://github.com/gaspa93/googlemaps-scraper/pull/38
Full Changelog: https://github.com/gaspa93/googlemaps-scraper/compare/v1.0.0...v1.1.0
- v1.0.02022-01-08 · 2022-01-08 13:16 UTC
查看更新说明
First version with two major features:
- Scrape reviews by URL up to 1200 reviews
- Integration with MongoDB to add new reviews incrementally
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Google Maps Scraper
Scraper of Google Maps reviews. The code allows to extract the most recent reviews starting from the url of a specific Point Of Interest (POI) in Google Maps. An additional extension helps to monitor and incrementally store the reviews in a MongoDB instance.
Installation
Follow these steps to use the scraper:
-
Download latest version of Chromedrive from here.
-
Install Python packages from requirements file, either using pip, conda or virtualenv:
conda create --name scraping python=3.9 --file requirements.txt
Note: Python >= 3.9 is required.
Basic Usage
The scraper.py script needs two main parameters as input:
--i: input file name, containing a list of urls that point to Google Maps place reviews (default: urls.txt)--o: output file name, which will be created in thedatafolder (default: output.csv)--N: number of reviews to retrieve, starting from the most recent (default: 100)
Example:
python scraper.py --N 50
generates a csv file containing last 50 reviews of places present in urls.txt
Additionally, other parameters can be provided:
--place: boolean value that allows to scrape POI metadata instead of reviews (default: false)--debug: boolean value that allows to run the browser using the graphical interface (default: false)--source: boolean value that allows to store source URL as additional field in CSV (default: false)--sort_by: string value among most_relevant, newest, highest_rating or lowest_rating (default: newest), developed by @quaesito and that allows to change sorting behavior of reviews
For a basic description of logic and approach about this software development, have a look at the Medium post
Monitoring functionality
The monitor.py script can be used to have an incremental scraper and override the limitation about the number of reviews that can be retrieved. The only additional requirement is to install MongoDB on your laptop: you can find a detailed guide on the official site
The script takes two input:
--i: same as monitor.py script--from-date: string date in the format YYYY-MM-DD, gives the minimum date that the scraper tries to obtain
The main idea is to periodically run the script to obtain latest reviews: the scraper stores them in MongoDB up to get either the latest review of previous run or the day indicated in the input parameter.
Take a look to this Medium post to have more details about the idea behind this feature.
Notes
Url must be provided as expected, you can check the example file urls.txt to have an idea of what is a correct url. If you want to generate the correct url:
- Go to Google Maps and look for a specific place;
- Click on the number of reviews in the parenthesis;
- Save the url that is generated from previous interaction.