为什么evaluateJavaScript只能运行一次?
我正在编写一个爬虫来爬取图像,它需要以编程方式单击菜单才能转到下一页。这是我在页面完成加载时的代码:
public slots:
void nextPage()
{
mainFrame()->evaluateJavaScript("readweb.nextPage()");
}
点击后,mainFrame应该加载一个指向下一个网页的新url(其中包含我想要抓取的图像)。但我发现它只在第一次有效。第一次点击后,第二次点击并没有导致新的url加载。网页的js脚本已经加载完毕,并且只加载了一次。
为什么它不起作用?有人有类似的情况吗?
I am writing an crawler to crawl images, which needs to programmatically click a menu to turn to the next page. Here is my code whenever a page finish loading:
public slots:
void nextPage()
{
mainFrame()->evaluateJavaScript("readweb.nextPage()");
}
After click, the mainFrame should load a new url point to the next webpage(which contains image I want to crawl). But I find it works only for the first time. After the first click, the second click didn't lead to a new url loading.The js scripts of the webpage has already loaded,and only load for one time.
Why it doesn't work? Anyone has similar situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的东西,但它不仅工作一次,而且每次调用都工作。
我现在的解决方法是一个假调用,例如:
webframe.evaluateJavaScript('return true;')
这会强制失败(在函数外部返回),并且下一个调用将按预期工作。
我不知道这个失败的调用是否会重置引擎或到底发生了什么。
I have soemthing similar, but it does not only work once, it works just every second call.
My workaround for now is a fake call like:
webframe.evaluateJavaScript('return true;')
This forces to fail (return outside a function) and the next call will work as it should.
I don't know if this failing call will reset the engine or what realy happens.
不知道这是否重要,但是您在声明末尾缺少分号?
Dont know if it matters or not, but you are missing a semicolon at the end of your statement?