用beautifulsoup-python调用onclick事件
invoking onclick event with beautifulsoup python
我正试图从这个网站获取塞浦路斯所有住宿的链接:http://www.zoover.nl/cyprus
到目前为止,我可以检索到已经显示的前15个。所以现在我必须调用"volgende"链接上的点击。然而,我不知道如何做到这一点,在源代码中,我无法追踪被调用的函数,例如,这里发布的类似内容:调用";点击事件";在html页面上使用Python 中的漂亮汤
我只需要"点击"发生的步骤,这样我就可以获取接下来的15个链接等等
有人知道怎么帮忙吗?已经谢谢了!
编辑:
我的代码现在看起来是这样的:
def getZooverLinks(country):
zooverWeb = "http://www.zoover.nl/"
url = zooverWeb + country
parsedZooverWeb = parseURL(url)
driver = webdriver.Firefox()
driver.get(url)
button = driver.find_element_by_class_name("next")
links = []
for page in xrange(1,3):
for item in parsedZooverWeb.find_all(attrs={'class': 'blue2'}):
for link in item.find_all('a'):
newLink = zooverWeb + link.get('href')
links.append(newLink)
button.click()'
我得到以下错误:
selenium.com.mon.exceptions.StaleElementReferenceException:消息:元素不再附加到DOMStacktrace:在fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:8956)在Utils.getElementAt(file:///var/folders/n4/fhvhqlmx23s8ppxbrxrpws3c0000gn/T/tmpKFL43_/extensions/fxdriver@googlecode.com/components/command processor.js:8546)在fxdriver.seconditions.visible(file:///var/folders/n4/fhvhqlmx23s8ppxbrxrpws3c0000gn/T/tmpKFL43_/extensions/fxdriver@googlecode.com/components/command processor.js:9585)在DelayedCommand.prototype.checkPreconditions(file:///var/folders/n4/fhvhqlmx23s8ppxbrxrpws3c0000gn/T/tmpKFL43_/extensions/fxdriver@googlecode.com/components/command processor.js:12257)在DelayedCommand.prototype.executeInternal/h(file:///var/folders/n4/fhvhqlmx23s8ppxbrxrpws3c0000gn/T/tmpKFL43_/extensions/fxdriver@googlecode.com/components/command processor.js:12274)在DelayedCommand.prototype.executeInternal(file:///var/folders/n4/fhvhqlmx23s8ppxbrxrpws3c0000gn/T/tmpKFL43_/extensions/fxdriver@googlecode.com/components/command processor.js:12279)在DelayedCommand.protype.execule/<(file:///var/folders/n4/fhvhqlmx23s8ppxbrxrpws3c0000gn/T/tmpKFL43_/extensions/fxdriver@googlecode.com/components/command processor.js:12221)
我很困惑:/
虽然使用Beautifulsoup的evaluateJavaScript
方法可能很诱人,但最终Beautifuuloup是一个解析器,而不是一个交互式web浏览客户端。
你应该认真考虑用硒来解决这个问题,如这个答案所示。有相当好的Python绑定可用于selenium。
您可以使用selenium找到元素并单击它,然后将页面传递给Beautifulsoup,并使用现有代码获取链接。
或者,您可以使用onclick处理程序中列出的Javascript。我从来源EntityQuery('Ns=pPopularityScore%7c1&No=30&props=15292&dims=530&As=&N=0+3+10500915');
中得到了这个。对于每一页,No
参数以15递增,但props
让我猜测。不过,我建议大家不要涉足这一领域,只需像客户一样使用硒元素与网站互动即可。这对他们这边的变化也更加有力。
我尝试了以下代码,并能够加载下一页。希望这对你也有帮助。代码:
from selenium import webdriver
import os
chromedriver = "C:'Users'pappuj'Downloads'chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
url='http://www.zoover.nl/cyprus'
driver.get(url)
driver.find_element_by_class_name('next').click()
感谢
- 如何在执行此特定onclick事件时执行JavaScript函数
- 如何调用“;链接_;在onclick事件上使用Javascript
- 如何使用jquery迭代具有相同属性的html元素并查找onclick事件
- 选择onclick事件jquery
- 如何刷新列表框内容onclick或blur事件
- 执行php函数的onclick事件的其他替代方案
- 动态创建OnClick事件Javascript
- onClick事件未触发reactjs
- 使用java脚本更改onClick事件中菜单选项卡的颜色
- 如何使用OnClick事件通过参数调用来调用PHP函数
- 第二个事件[onClick]不起作用
- 复选框事件onclick不起作用
- 如何在jQuery中为通知添加事件onClick
- JS函数不响应事件onclick
- 使用事件onclick访问if语句Javascript中变量的值
- 如何在事件onclick中抓取文本
- 如何绑定id < light >与事件Onclick
- 未找到JS事件OnClick
- 如何在js/prototype中触发具有特定顺序的事件(onclick)
- 无法触发javascript事件OnClick的复选框