Hi guys,
I am developing a program for extracting the hotels details from the hotelscombined. however, as per my trial, all texts including hotels name, location, service etc can be extracted under <div @class='hc_sr_summary>. However, if I just wanna get the hotels name. How can I make it?
In my trial, news2 = browser.find_element_by_xpath("//div[@id='u1']").text <--this can extract first hotel name only; for the rest, cannot be extracted.
I guess it is the loop issue. because the structure is as below. Please help to answer my question. Thank you.
<div class='hc_sr_summary'> <= master level
<div id='uniquehotelID1' class='hc-searchresultitem'> <== child level
<div class="hc-searchresultitem__hotelsummary">
<H3 class="hc-searchresultitem__hotelname">
<a id="searchResultHeading2679577" class="hc-searchresultitem__hotelnamelink" ....>Hotel Midtown Richardson</a>
<div id='uniquehotelID2' class='hc-searchresultitem'> <== child level
<div id='uniquehotelID3' class='hc-searchresultitem'> <== child level
<div id='uniquehotelID4' class='hc-searchresultitem'> <== child level
************************
I am developing a program for extracting the hotels details from the hotelscombined. however, as per my trial, all texts including hotels name, location, service etc can be extracted under <div @class='hc_sr_summary>. However, if I just wanna get the hotels name. How can I make it?
In my trial, news2 = browser.find_element_by_xpath("//div[@id='u1']").text <--this can extract first hotel name only; for the rest, cannot be extracted.
I guess it is the loop issue. because the structure is as below. Please help to answer my question. Thank you.
<div class='hc_sr_summary'> <= master level
<div id='uniquehotelID1' class='hc-searchresultitem'> <== child level
<div class="hc-searchresultitem__hotelsummary">
<H3 class="hc-searchresultitem__hotelname">
<a id="searchResultHeading2679577" class="hc-searchresultitem__hotelnamelink" ....>Hotel Midtown Richardson</a>
<div id='uniquehotelID2' class='hc-searchresultitem'> <== child level
<div id='uniquehotelID3' class='hc-searchresultitem'> <== child level
<div id='uniquehotelID4' class='hc-searchresultitem'> <== child level
************************
from selenium import webdriver browser = webdriver.Firefox() browser.get('https://www.hotelscombined.hk/Hotels/Search?destination=place%3ATaipei&checkin=2019-05-05&checkout=2019-05-06&Rooms=1&adults_1=2&languageCode=HK¤cyCode=HKD#destination=place:Taipei&radius=0km&checkin=2019-05-05&checkout=2019-05-06&Rooms=1&adults_1=2&pageSize=15&pageIndex=1&sort=Popularity-desc&showSoldOut=false&scroll=432&HotelID=&mapState=expanded%3D0') ##Get all text from <div @class='hc_sr_summary> news = browser.find_element_by_xpath("//div[@class='hc_sr_summary']").text print (news) ##Get 1st <h3> under <div @class='hc_sr_summary> rather than all <h3>??? news2 = browser.find_element_by_xpath("//h3[@class='hc-searchresultitem__hotelname']").text print (news2) #browser.close()