This script is designed to scrape hotel prices from Google Travel for a list of hotels and dates. It uses the Playwright library to automate the process of searching for hotels, filling in dates, and extracting prices from various online travel agencies (OTAs).
- CSV Input: Reads data from a CSV file where the input values (such as dates) can be stored.
- Date Filling: Automatically fills check-in and check-out date fields on web forms.
- Web Scraping: Uses Playwright to interact with web elements and extract data.
Python 3.7+
Playwright library
pip install playwright
Pandas library
pip install pandas
CSV library
pip install csv
- Clone the repository and navigate to the project directory.
- Install the required libraries by running
pip install -r requirements.txt
- Update the CheckinDates list in the script with the desired dates.
CheckinDates = [
"9/25/2024",
"9/26/2024"
]
- Update the file_path variable with the path to your hotel list CSV file.
- Run the script using python main.py.
Table file_path .csv as file_path:
HotelName | Checkin-Date |
---|---|
Hotel 1 | 09/25/2024 |
Hotel 2 | 09/25/2024 |
The script will output an Excel file named shoprateResult.xlsx containing the scraped data. Table save_data .xlsx as Shoprate Result:
Hotel | Checkin Date | Checkout Date | Agoda | Booking.com |
---|---|---|---|---|
Hotel 1 | 09/25/2024 | 09/26/2024 | PriceTHB | PriceTHB |
Hotel 1 | 09/26/2024 | 09/27/2024 | PriceTHB | PriceTHB |
Hotel 2 | 09/25/2024 | 09/26/2024 | PriceTHB | PriceTHB |
Hotel 2 | 09/26/2024 | 09/27/2024 | PriceTHB | PriceTHB |