问题描述
我已经在 SO 上浏览了各种线程,但到目前为止它对我没有用。
我正在使用以下代码:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
xPathFull = r'/html/body/div[2]/div[2]/div[1]/div[1]/div/form/div[2]/div[2]/input'
path_to_chromedriver = r'C:\chromedriver' # change path as needed
browser = webdriver.Chrome(executable_path=path_to_chromedriver)
.........
.........
content = browser.find_element_by_xpath(xPathFull).text
我尝试从中复制文本的位置的 html 是:
<input name="shortLink" type="text" value="https://shrsl.com/2dsda" onfocus="this.select();" readonly="">
基本上我希望上面的 content
变量存储值 https://shrsl.com/2dsda
解决方法
试试:
content = browser.find_element_by_xpath(xPathFull).get_attribute('value')