通过搜索父元素返回HREF -Selenium Python

问题描述 投票:0回答:1

我对编码/硒相当陌生

我试图通过搜索其父元素之一来获取 href 链接列表 我相信我需要这样做,因为该网站有大量链接副本,因此搜索任何 href 都会给我一个很长的副本列表。

理想情况下,我希望它制作一个链接列表

我已经被困在这个问题上几个小时了,对任何形式的帮助都很满意

我试过这个 links = driver.find_element(By.XPATH,'//div[@data-testid="card-container"//a[@href]')

This is an example of the HTML. Is it possible to get the HRF by searching by the data-testid=

网站链接: https://www.airbnb.com.au/s/黄金海岸--QLD/homes?place_id=ChIJt2BdK0cakWsRcK_e81qjAgM&refinement_paths%5B%5D=%2Fhomes&checkin=2024-12-22&checkout=2024-12-28&date_picker_type=calendar&adults=9儿童&儿童=2&pets=1&search_type=user_map_move&tab_id=home_tab&query=Gold%20Coast%2C%20QLD&flexible_trip_lengths%5B%5D=one_week&monthly_start_date=2024-08-01&monthly_length=3&monthly_end_date=2024-11-01&search_mode=regular_search&price_filter_input_type=2 &price_filter_num_nights=6&channel=探索&ne_lat=-27.8312213554841&ne_lng=153.85466017727208 &sw_lat=-28.314709414353157&sw_lng=153.3574718233147&zoom=10.257561001998951&zoom_level=10.257561001998951&search_by_map=true&price_min=8683&price_max=14459&最小卧室数=5

python html selenium-webdriver href
1个回答
0
投票

driver.find_elements(By.XPATH,'//后代::div[@data-testid="card-container"]//a[@href]')

© www.soinside.com 2019 - 2024. All rights reserved.