我使用下面的Python代碼從文本框中提取文本從文本框中提取文本的Python /硒 - 無法
def check():
with open("LP_input.txt") as f:
for line in f:
url = line.strip()
driver.get(url)
driver.wait = WebDriverWait(driver, 10)
time.sleep(10)
PC = driver.find_elements_by_xpath("//div[@id='wwctrl_landingPageDataForm_attributeMap_STRUCTURE_DATA_REQUIRED']")
for x in PC:
print(x)
我的HTML(網頁,我中提取文本)
<div id="wwctrl_landingPageDataForm_attributeMap_STRUCTURE_DATA_REQUIRED" class="wwctrl">
<input id="landingPageDataForm_attributeMap_STRUCTURE_DATA_REQUIRED" class="text medium" name="attributeMap.STRUCTURE_DATA_REQUIRED" maxlength="1000" value="TRUE" style="" type="text"
,但我得到這個錯誤;
<selenium.webdriver.remote.webelement.WebElement (session="9f5789eaeb8dbd5cc005dc63e3d4f9f2", element="0.6714808439487934-1")>
其實文本框將包含TRUE或FALSE ..我想提取此爲數千頁。
這不是錯誤,即硒元素對象,解決你的問題是,從該元素獲取文本做'PC.text()',而不是運行一個for循環 – Stack
@Stack嘗試使用的.text ()仍然發行n ot解決..現在程序關閉,沒有顯示錯誤..但輸出沒有收到..我猜xpath是罪魁禍首.. – Abdul
只是最後添加一個額外的輸入,腳本工作正常,終端在最後快速關閉。因此,僅僅通過增加投入,將工作 – Stack