【发布时间】:2014-02-09 18:50:18
【问题描述】:
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"]')
现在超越这一点是:
表 xmlns:msxsl="urn:schemas-microsoft-com:xslt" width="100%"
现在,我注意到这会阻止我直接通过 xpath 访问表格内容。
所以我的问题是: 如何交互或提取此表的内容?
编辑: 尝试访问表的 xpath 或其内容会抛出“noSuchElementException”,执行此操作的代码行是:
eli=elem.find_element_by_xpath('//*[@id="ReportHolder"]/table')
(注意:我无法提供准确的 html 访问权限,因为它是受公司密码保护的位置。)
有没有人遇到过类似的问题?或者任何人都可以注意到 xpath 有什么不妥之处(即使它是直接的副本检查)。
编辑2: 提取自的简化示例 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?我不明白为什么会这样。
-
如果您无法提供完整的文档,请提供一个示例您的代码失败。问题无法按原样回答。
标签: python xslt selenium xpath python-3.x