![](/img/trans.png)
[英]How can I extract the content from a div using python + selenium
[英]How to extract text from div class using Selenium with Python
我正在嘗試創建一個機器人來自動支付一些賬單。 問題是我無法提取 div class 下的金額(文本)。 錯誤是未找到元素。 使用了 driver.find_element_by_xpath 和 WebDriverWait。 您能否指出如何獲得突出顯示的文本 - 請參閱附件鏈接? 提前致謝。 Page_inspect
您可以使用 -
driver.find_element_by_xpath("//div[@data-ng-bind-html='vm.productList.totalAmt']").text
我已經根據您所附的圖片編寫XPath
。 使用列表索引獲取目標 div。 例如 -
driver.find_element_by_xpath("(//div[@data-ng-bind-html='vm.productList.totalAmt'])[1]").text
我相信您的 xpath 存在一些問題。 在下面嘗試它應該可以工作:
amount = WebDriverWait(self.driver, self.timeout).until( EC.presence_of_element_located((By.XPATH, '//div[starts-with(@class,"bill-summary-total")]//div[contains(@data-ng-bind-html,"vm.productList.totalAmt")]')))
print('Your amount is: {}'.format(amount.text))
return float(amount.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.