Selenium find_elements_ from a tag

后端 未结 2 867
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 06:01

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 followin

相关标签:
2条回答
  • 2021-01-29 06:45

    Welcome to SO. Here is the simple approach to get the number of vacant rooms.

    # get all the vacant room elements
    rooms = driver.find_elements_by_xpath("//span[@class='only_x_left sr_rooms_left_wrap ']")
    for room in rooms:
        # get the number of elements
        print(room.get_attribute('data-x-left-count'))
    
    0 讨论(0)
  • 2021-01-29 07:01

    Assuming that attribute is only associated with rooms left you can simply use attribute selector

    rooms_left = [item.get_attribute('data-x-left-count') for item in driver.find_elements_by_css_selector("[data-x-left-count]")]
    
    0 讨论(0)
提交回复
热议问题