I'm trying to compile a list of links within a page. However, when printing the list the output is a bunch of random numbers
links = driver.find_elements(By.CSS_SELECTOR, "meta[content*='www.airbnb.com.au/rooms/']")
print(links)
Example output:
[<selenium.webdriver.remote.webelement.WebElement (session="faf70ce53ba59d6f6995883b0edfc006", element="f.CD9BA18B85DC3350F27BC5BF71FF60B2.d.5C798985F0B6BFD4214898A37DFC2A30.e.81")>, <selenium.webdriver.remote.webelement.WebElement (session="faf70ce53ba59d6f6995883b0edfc006", element="f.CD9BA18B85DC3350F27BC5BF71FF60B2.d.5C798985F0B6BFD4214898A37DFC2A30.e.82")>, <selenium.webdriver.remote.webelement.WebElement (session="faf70ce53ba59d6f6995883b0edfc006", element="f.CD9BA18B85DC3350F27BC5BF71FF60B2.d.5C798985F0B6BFD4214898A37DFC2A30.e.83")>, <selenium.webdriver.remote.webelement.WebElement (session="faf70ce53ba59d6f6995883b0edfc006", element="f.CD9BA18B85DC3350F27BC5BF71FF60B2.d.5C798985F0B6BFD4214898A37DFC2A30.e.84")>]
The website im trying to scrape:
print(links)
You are just printing the list
object which has web elements. To get the URLs from the target elements, you should capture the content
attribute's value.
Try this:
for link in links:
print(link.get_attribute("content"))
Output:
www.airbnb.com.au/rooms/50961691?adults=9&children=2&pets=1&search_mode=regular_search&check_in=2024-12-22&check_out=2024-12-28&source_impression_id=p3_1720094600_P3E3TFbSLV_F8Hv-&previous_page_section_name=1000
www.airbnb.com.au/rooms/10732858?adults=9&children=2&pets=1&search_mode=regular_search&check_in=2024-12-22&check_out=2024-12-28&source_impression_id=p3_1720094600_P3xqAumg9A_T_K_Z&previous_page_section_name=1000
www.airbnb.com.au/rooms/25083963?adults=9&children=2&pets=1&search_mode=regular_search&check_in=2024-12-22&check_out=2024-12-28&source_impression_id=p3_1720094600_P3LxjqyKDwEQn8FV&previous_page_section_name=1000
www.airbnb.com.au/rooms/1112833302463251442?adults=9&children=2&pets=1&search_mode=regular_search&check_in=2024-12-22&check_out=2024-12-28&source_impression_id=p3_1720094600_P3NtINEuiRiA5r4F&previous_page_section_name=1000
Process finished with exit code 0