python - 如何从 Python 中的 OuterHTML 中提取值
问题描述
<a id="ctl00_ctl00_ctl00_c_hdetail_lblPat2" href="javascript:popupPatient(218809, '0');">CHATARPAL, LALITA</a>
我正在尝试从outerHTML 中获取文本(218809)。早些时候我用 AHK 做同样的事情,但现在我正在学习 Python 做同样的事情。
这是我的代码。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import re
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
driver.get("https://brightree.net/F1/0375/MBSNI/Receipts/Invoices/Invoice_Invoice.aspx?InvoiceKey=3729668")
wait=WebDriverWait(driver,10)
wait.until(EC.element_to_be_clickable((By.XPATH,"//*[@id='ctl00_ctl00_ctl00_c_hdetail_lblSalesOrder2']")))
Target=driver.find_element_by_id("ctl00_ctl00_ctl00_c_hdetail_lblPat2")
Get_Value=Target.get_attribute("outerHTML")
print(Get_Value)
解决方案
Get_Value=Target.get_attribute("href")
Get_Value=re.findall('\d+', Get_Value)[0]
print(Get_Value)
使用正则表达式 \d 查找数字, \d+ 表示一位或多位数字
推荐阅读
- javascript - 使用当前 vue 组件的方法作为默认 prop 值
- ruby - 使用 will_paginate 分页没有活动记录只显示第一页的值,下一页完全为空
- python - 如何使用交互方法构建模块
- r - 有人可以协助在 R 中使用“httr”包进行 API 调用吗?
- python - 如何在 matplotlib 中将列指定为轴并绘制条形图?
- azure - 如何通过 FQDN 寻址 VNET 中的其他 VM?
- java - 如何将http响应放入Set
- database - 如何从远程 Db2 实例连接到 IBM Db2 Event Store 实例?
- html - 折叠的表行继承父级的背景颜色
- database - 在.net core web api服务中为每个get/post请求使用数据库连接的最佳方式