久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python Selenium - 獲取href值

Python Selenium - get href value(Python Selenium - 獲取href值)
本文介紹了Python Selenium - 獲取href值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試從網站復制 href 值,html 代碼如下所示:

I am trying to copy the href value from a website, and the html code looks like this:

<p class="sc-eYdvao kvdWiq">
 <a href="https://www.iproperty.com.my/property/setia-eco-park/sale- 
 1653165/">Shah Alam Setia Eco Park, Setia Eco Park
 </a>
</p>

我試過 driver.find_elements_by_css_selector(".sc-eYdvao.kvdWiq").get_attribute("href") 但它返回 'list' 對象沒有屬性 'get_attribute'.使用 driver.find_element_by_css_selector(".sc-eYdvao.kvdWiq").get_attribute("href") 返回 None.但我不能使用 xpath,因為該網站有 20+ href 我需要全部復制.使用 xpath 只會復制一個.

I've tried driver.find_elements_by_css_selector(".sc-eYdvao.kvdWiq").get_attribute("href") but it returned 'list' object has no attribute 'get_attribute'. Using driver.find_element_by_css_selector(".sc-eYdvao.kvdWiq").get_attribute("href") returned None. But i cant use xpath because the website has like 20+ href which i need to copy all. Using xpath would only copy one.

如果有幫助,所有 20 多個 href 都歸入同一類,即 sc-eYdvao kvdWiq.

If it helps, all the 20+ href are categorised under the same class which is sc-eYdvao kvdWiq.

最終我想復制所有 20+ href 并將它們導出到 csv 文件.

Ultimately i would want to copy all the 20+ href and export them out to a csv file.

感謝任何可能的幫助.

推薦答案

如果有多個元素,您需要 driver.find_elements.這將返回一個列表.對于 CSS 選擇器,您要確保選擇那些具有子 href 的類

You want driver.find_elements if more than one element. This will return a list. For the css selector you want to ensure you are selecting for those classes that have a child href

elems = driver.find_elements_by_css_selector(".sc-eYdvao.kvdWiq [href]")
links = [elem.get_attribute('href') for elem in elems]

您可能還需要一個等待條件來等待由 css 選擇器定位的所有元素.

You might also need a wait condition for presence of all elements located by css selector.

elems = WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".sc-eYdvao.kvdWiq [href]")))

這篇關于Python Selenium - 獲取href值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 日韩av成人在线 | 黄色成人免费网站 | 黄色成人av | 亚洲第一免费视频 | 91在线精品秘密一区二区 | 久久久久网 | 一区二区不卡视频 | av综合网站 | 中文字幕在线视频观看 | 又色又爽又黄18网站 | av超碰在线 | 亚洲一区二区三区在线 | 91在线视频观看 | 国产超碰人人模人人爽人人添 | 黄色三级在线 | 日韩一级视频 | 欧美激情精品 | 日本在线精品 | 日本伊人 | 日韩大片在线观看 | 日韩一区三区 | 曰本毛茸茸性生活 | 精品三级在线观看 | 精品成人av| 黄色片视频免费 | 国产欧美综合一区二区三区 | 又色又爽又黄gif动态图 | 国产福利视频 | 亚洲免费专区 | 国产一区二区视频在线观看 | 老女人丨91丨九色 | 日韩精品在线观看视频 | 日韩视频在线免费观看 | 天天操操操 | 在线免费观看av网站 | 成人午夜小视频 | www国产在线观看 | 在线观看福利影院 | 黄网免费看 | 亚洲黄色片| 日本丰满肉感bbwbbwbbw |