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

如何使用 Selenium 和 Python 從文本節(jié)點中檢索部分

How to retrieve partial text from a text node using Selenium and Python(如何使用 Selenium 和 Python 從文本節(jié)點中檢索部分文本)
本文介紹了如何使用 Selenium 和 Python 從文本節(jié)點中檢索部分文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我只想獲取文本..."而不使用 .split() 或索引切片

I want to get only " text ... " not using .split() or index slicing

HTML:

<a class="call_recipe" href="/recipes/2913">
      " text ... "
      <strong> something~ </strong>
    </a>

HTML 快照:

推薦答案

要打印 text ... 你必須誘導 WebDriverWait 用于 visibility_of_element_located() 并且您可以使用以下任一 定位器策略:

To print text ... you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • 使用 CSS_SELECTOR、childNodesstrip():

print(driver.execute_script('return arguments[0].firstChild.textContent;', WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.call_recipe[href^='/recipes']")))).strip())

  • 使用 XPATH、get_attribute()splitlines():

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@class='call_recipe' and starts-with(@href, '/recipes')]"))).get_attribute("innerHTML").splitlines()[1])
    

  • 注意:您必須添加以下導入:

  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

  • 您可以在以下位置找到一些相關(guān)的詳細討論:

    You can find a couple of relevant detailed discussions in:

    • 如何獲取特定文本屬于 div 類
    • 如何使用 Selenium 和 Python 從由空格分隔的文本節(jié)點獲取文本

    這篇關(guān)于如何使用 Selenium 和 Python 從文本節(jié)點中檢索部分文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

    相關(guān)文檔推薦

    How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
    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(根據(jù)文本方向檢測圖像方向角度)
    Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
    主站蜘蛛池模板: 秋霞福利视频 | 日本精品国产 | 天天干天天色天天射 | 日本成人小视频 | 国产一区二区影院 | 黑人精品一区二区 | 不卡的av在线 | 毛片视频免费 | 四虎wz | 黄色片免费 | 日韩免费毛片 | 国产人妖在线 | 国产又粗又长又爽 | 亚洲成人免费在线观看 | 欧美成人免费在线视频 | 在线观看亚洲一区 | 欧美日韩在线视频观看 | 免费一区二区 | av手机在线免费观看 | 国产精品一品二区三区的使用体验 | 久久精品福利视频 | 日韩中文视频 | av超碰在线| 国产一区二区影院 | 182tv午夜| 国产理论视频 | 日韩精品一区在线观看 | 99视频网| 久久在线精品 | 国产精品偷乱一区二区三区 | 在线观看免费av网站 | 三年中文在线看免费观看 | 久久人人爽人人爽人人片 | www.天天干| 久久国产一区二区三区 | 中文字幕在线观看第一页 | 国产一区二区三区精品视频 | 操操操av | av一二三区 | 欧美视频在线播放 | 天天天天躁天天爱天天碰2018 |