【问题标题】:How can I get next page javascript button using python如何使用 python 获取下一页 javascript 按钮
【发布时间】:2015-03-30 18:20:30
【问题描述】:

我正在使用 Python 获取使用以下 HTML 代码引用的下一页:

<td xmlns="http://www.w3.org/1999/xhtml" 
class="rich-datascr-button"
onclick="Event.fire(this, 'rich:datascroller:onscroll', {'page': 'next'});">
<br _moz_dirty="" type="_moz"/></td>

我一直在尝试不同的选择,但都没有奏效。

【问题讨论】:

  • 那么你尝试了什么?
  • 提示:当您在浏览器中单击 next 链接时,我会检查请求的 http 标头。以某种方式尝试从当前页面中的数据生成该 URL 并发送第二个查询。

标签: javascript python


【解决方案1】:

我一直在处理 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">&#171;&#171;</td>
<td class="rich-datascr-button-dsbld rich-datascr-button">&#171;</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'});">&#187;</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 弄清楚。我的问题是在表格中获取网页。

【讨论】:

  • 这属于问题,不作为单独的答案。
猜你喜欢
  • 1970-01-01
  • 2012-10-19
  • 1970-01-01
  • 2017-05-10
  • 2023-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-18
相关资源
最近更新 更多