This scraper is using scrapfly.io and Python to scrape data from tripadvisor.com.
Full tutorial https://scrapfly.io/blog/how-to-scrape-tripadvisor/
The scraping code is located in the tripadvisor.py
file. It's fully documented and simplified for educational purposes and the example scraper run code can be found in run.py
file.
This scraper scrapes:
- TripAdvisor search for finding hotels from search queries. e.g. https://www.tripadvisor.com/Hotels-g190311-Malta-Hotels.html
- TripAdvisor hotel listing details:
e.g. https://www.tripadvisor.com/Hotels-g190311-Malta-Hotels.html- hotel info: description, rating, features etc.
- prices
- reviews
For output examples see the ./results
directory.
Note that this code is provided free of charge as is, and Scrapfly does not provide free web scraping support or consultation. For any bugs, see the issue tracker.
This Tripadvisor scraper uses Python 3.10 with scrapfly-sdk package which is used to scrape and parse Tripadvisor's data.
- Ensure you have Python 3.10 and poetry Python package manager on your system.
- Retrieve your Scrapfly API key from https://scrapfly.io/dashboard and set
SCRAPFLY_KEY
environment variable:$ export SCRAPFLY_KEY="YOUR SCRAPFLY KEY"
- Clone and install Python environment:
$ git clone https://github.com/scrapfly/scrapfly-scrapers.git $ cd scrapfly-scrapers/tripadvisor-scraper $ poetry install
- Run example scrape:
$ poetry run python run.py
- Run tests:
$ poetry install --with dev $ poetry run pytest test.py # or specific scraping areas $ poetry run pytest test.py -k test_hotel_scraping $ poetry run pytest test.py -k test_search_scraping $ poetry run pytest test.py -k test_location_data_scraping