我一直在处理 Selenium,它是 Brouser 和 Mechanize 的碎片。我知道机械化不是办法。
最近我一直在尝试这样的事情:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
driver.implicitly_wait(10)
# go to the google home page
driver.get(url)
element =driver.find_element_by_xpath("//td[contains(.,'???')]")
print element
我试图从页面中获取的表格部分是由
发出的信号
<td class=" rich-datascr-button" onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': 'next'});"></td>
页面中的表格如下所示:
<div class="rich-datascr " id="tpForm:scroll2" style=" " align="center">
<table border="0" cellpadding="0" cellspacing="1" class="rich-dtascroller-table " id="tpForm:scroll2_table" style="text-align:center">
<tbody>
<tr>
<td class="rich-datascr-button-dsbld rich-datascr-button">««</td>
<td class="rich-datascr-button-dsbld rich-datascr-button">«</td>
<td class="rich-datascr-button-dsbld rich-datascr-button"></td>
<td class="rich-datascr-act ">1</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '2'});">2</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '3'});">3</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '4'});">4</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '5'});">5</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '6'});">6</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '7'});">7</td>
<td class="rich-datascr-inact " onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': '8'});">8</td>
<td class=" rich-datascr-button" onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': 'next'});"></td>
<td class=" rich-datascr-button" onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': 'fastforward'});">»</td>
<td class=" rich-datascr-button" onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': 'last'});">Last</td>
</tr>
</tbody>
</table>
<script type="text/javascript">new Richfaces.Datascroller('tpForm:scroll2', function(event){A4J.AJAX.Submit('tpForm',event,{'ignoreDupResponses':true,'implicitEventsQueue':'tpForm:scroll2','similarityGroupingId':'tpForm:scroll2','parameters':{'tpForm:scroll2':event.memo.page,'ajaxSingle':'tpForm:scroll2'} } ); return false;});</script>
</div>
我希望通过 Python 中的代码获取表格的下一部分,以访问每个部分的引用列表。我可以在最后一点使用 urlparse、BeautifulSoup 和 urllib2 弄清楚。我的问题是在表格中获取网页。