import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from datetime import datetime, timedelta
from tkinter import StringVar, messagebox, Entry, Tk
chromeOps=webdriver.ChromeOptions()
chromeOps._binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
chromeOps._arguments = ["--enable-internal-flash"]
browser = webdriver.Chrome("C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe", port=4445, chrome_options=chromeOps)
time.sleep(3)
browser.get('website')
elem=browser.find_element_by_id('MainForm')
eli=elem.find_element_by_xpath('//*[@id="ReportHolder"]')
現在超過該點是:的Python - 硒 - Webscrape表
表的xmlns:msxsl = 「甕:架構 - 微軟-COM:XSLT」 WIDTH = 「100%」
現在,我注意到這阻止了我直接對錶內容進行xpath處理。
所以我的問題是: 如何交互或提取此表的內容?
編輯: 試圖訪問表的XPath或內容拋出一個「NoSuchElementException異常」,代碼行,這是否是:
eli=elem.find_element_by_xpath('//*[@id="ReportHolder"]/table')
(注:我不能給出確切的html因爲它是公司密碼保護位置。)
有沒有人遇到過類似的問題?或者任何人都可以注意到有關xpath的一些不當之處(即使它是直接複製檢查)。
EDIT2: 簡單的例子XHTML從 http://s1362.photobucket.com/user/superempl/media/roady2_zps3e1430d2.png.html
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>XPath</title>
</head>
<body>
<form name="MainForm" method="post" action="hidden" id="MainForm">
<div id="ReportHolder">
<table xmlns:msxml="urn:schemas-microsoft-com:xslt" width="100%">
<tr><td></td></tr>
</table>
</div>
</form>
</body>
</html>
請在您的問題中添加相關的html部分 –
它如何防止您使用XPath?我不明白爲什麼會這樣。 – Arran
如果您無法提供完整的文檔,請提供一個示例__對您的code_失敗。這個問題不能按原樣回答。 –