【发布时间】:2014-01-21 11:32:12
【问题描述】:
<html xmlns="hyyp://www.w3.org/1999/xhtml">
<head>_</head>
<body>
<form name="Main Form" method="post" action="HTMLReport.aspx?ReportName=...">
<div id="Whole">
<div id="ReportHolder">
<table xmlns:msxsl="urn:schemeas-microsoft-com:xslt" width="100%">
<tbody>
<tr>
<td>_</td>
<td>LIVE</td>
and the data I need is here between <td> </td>
现在我的代码是:
import time
from selenium import webdriver
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')
el=elem.find_element_by_xpath('//*[@id="ReportHolder"]')
最后两行代码实际上是我测试在 xpath 崩溃之前我可以走的路径。尝试对超出此点的任何内容进行 xpath 会产生 noSuchElementException。
谁能解释一下我是如何从表格中提取数据的?
我目前的想法是,也许我必须将“某些东西”传递到 xml 树 api 并通过它访问它。虽然不知道怎么拍。
如果有人能给我下一步的工作,我将不胜感激,感觉有点像我此刻在黑暗的房间里拿着蜡烛。
【问题讨论】:
-
澄清一下,如果您使用 xpath,例如:
driver.find_element_by_xpath("//div[@id='ReportHolder']/table/tbody/tr"),您会收到异常吗? -
是的,这是正确的。在我的示例中: el=browser.find_element_by_xpath('//*[@id="ReportHolder"]/table/tbody/tr') 产生 noSuchElementException