I want to scrape some hotel information from Booking.com. The website provides some hotel informations, in this particular case, how many rooms are still available. The following shows the span tag from the Booking.com website and i want to extract only the number of data-x-left-count for all listed hotels.
<span class="only_x_left sr_rooms_left_wrap " data-x-left-count="6">
Nur noch 6 Zimmer auf unserer Seite verfügbar!
</span>
I tried to approach it by finding the elements and returning an array of selenium objects.
availabilities_element = browser.find_elements_by_xpath("(//span[contains(.,'nur noch')])[2]")
And then a list comprehension to get the actual hotel titles and not the selenium objects.
availabilities = [x.text for x in availabilities_element]
But i have still some problems to get the data. I expect to get a list (just the numbers and nothing more) of the available rooms. Is there a way for a clean simple solution?
Assuming that attribute is only associated with rooms left you can simply use attribute selector
Welcome to SO. Here is the simple approach to get the number of vacant rooms.