Scraping the availability and coordinates from Booking.com

Viewed 28

I am working on a project for my personal portfolio and I want to scrape the availability from booking.com and the coordinates of a every listing.

I manage to scrape other info like price, address, title etc.

For the availability first of all I need to click on the calendar (the one below in the page please check on the link). I am trying to locate my code to click there but unfortuntely it clicks in the above calendar. Then I need some help on how can I scrape if a date is available or not.

Regarding the coordinates i couldn't find where are the coordinates in booking.com even if I click in the map.

This is the link: Booking Link

This is my imports:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from bs4 import BeautifulSoup
import pandas as pd
import time
import re
import requests

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()

This is how I can click on the calendar (then I will follow a similar loop like the one below i guess) :

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
wait = WebDriverWait(driver,20)
test_url = 'https://www.booking.com/hotel/gr/vanoro.en-gb.html?aid=304142&label=gen173nr-1DCAEoggI46AdIM1gEaFyIAQGYAQm4ARjIAQzYAQPoAQGIAgGoAgS4Apmc_ZgGwAIB0gIkOWY1YjcyNjItMzkxNi00ZThjLTg2MWItNjdjNDIzYTkyYTNl2AIE4AIB&sid=47583bd8c0122ee70cdd7bb0b06b0944&all_sr_blocks=742081905_329262610_2_41_0;checkin=2022-09-30;checkout=2022-10-01;dest_id=-829252;dest_type=city;dist=0;group_adults=2;group_children=0;hapos=3;highlighted_blocks=742081905_329262610_2_41_0;hpos=3;matching_block_id=742081905_329262610_2_41_0;no_rooms=1;req_adults=2;req_children=0;room1=A%2CA;sb_price_type=total;sr_order=popularity;sr_pri_blocks=742081905_329262610_2_41_0__11254;srepoch=1662996947;srpvid=f3bd6da86d650372;type=total;ucfs=1&#map_closed'
driver.get(test_url)
time.sleep(3)
soup2 = BeautifulSoup(driver.page_source, 'lxml')
date=[]
blocked = []
button = driver.find_element(By.CSS_SELECTOR, 'span.js-date-field__value')
driver.execute_script('arguments[0].click()', button)
#xpath = '//div[@aria-labelledby="bui-calendar-1662997472878bskkddv"]//div[@aria-label]'
#for item in driver.find_elements(By.XPATH, xpath):
#       date.append(item.get_attribute("aria-label"))
#      blocked.append(item['calendar-day__price'])

Can anyone help on this please, I couldn't find big documentation about booking.com on the net.

Thanks.

0 Answers
Related