我正在尝试使用Python中的Selenium来存储表格内容。以下是我的脚本:
这将打开我感兴趣的网页,然后应该保存我想要的表格内容。我看到了这个问题中使用了
import sys
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://testsite.com")
value = selenium.getTable("table_id_10")
print value
driver.close()
这将打开我感兴趣的网页,然后应该保存我想要的表格内容。我看到了这个问题中使用了
browser.get_table()
的语法,但那个程序的开头是browser=Selenium(...)
,我不明白。我不确定我应该使用什么语法,因为selenium.getTable("table_id_10")
是错误的。
编辑:
我包含了一个我正在使用的表格的html片段:
<table class="datatable" cellspacing="0" rules="all" border="1" id="table_id_10" style="width:70%;border-collapse:collapse;">
<caption>
<span class="captioninformation right"><a href="Services.aspx" class="functionlink">Return to Services</a></span>Data
</caption><tr>
<th scope="col">Read Date</th><th class="numericdataheader" scope="col">Days</th><th class="numericdataheader" scope="col">Values</th>
</tr><tr>
<td>10/15/2011</td><td class="numericdata">92</td><td class="numericdata">37</td>
</tr><tr class="alternaterows">
<td>7/15/2011</td><td class="numericdata">91</td><td class="numericdata">27</td>
</tr><tr>
<td>4/15/2011</td><td class="numericdata">90</td><td class="numericdata">25</td>
</table>