运行一个源';使用phantomJS创建javascript
我想做以下工作:运行一个源';使用phantomJS创建javascript,javascript,phantomjs,web-crawler,Javascript,Phantomjs,Web Crawler,我想做以下工作: 访问网站 单击按钮=>javascript函数将更改部分html 获取新更改的html的一些内容 所有这些都是自动的 我尝试了为nodejs提供的几种工具,包括和 目前,我在PhantomJS中运行了这段代码 page.open('https://www.thegioididong.com/dtdd/iphone-x-256gb', function (status) { console.log("Status: " + status); var a = pa
page.open('https://www.thegioididong.com/dtdd/iphone-x-256gb', function (status) {
console.log("Status: " + status);
var a = page.evaluate(function () {
document.getElementsByClassName("viewparameterfull")[0].click()
console.log(document.getElementsByClassName('parameterfull')[0].textContent)
return document.getElementsByClassName('parameterfull')[0].textContent
})
phantom.exit();
})
结果是
Status: success
ReferenceError: Can't find variable: getFullSpec
使用Chrome调试器,我可以看到getFullSpec
是一个函数:
- 单击代码中选定的按钮时激发
- 可以在页面加载时下载的另一个
文件中找到js
- 当
打开带有PhantomJS
的链接时,它是否像浏览器一样加载每个文件(js、css…)page.open()
- 如果有,我如何使用
运行PhantomJS
(包含在另一个getFullSpec
文件中)js
您可以打开页面,打开devtools,在js源代码中搜索代码。感谢您的快速响应!你的意思是我可以使用PhantomJS来做这件事,但我的代码中有错误?你能告诉我如何修复它吗?这是页面js文件中的错误。我不知道如何修复,可能getFullSpec尚未初始化。所以在点击之前试着设置延迟。对不起,我不知道我是否理解正确。如果你的意思是源代码的javascript有错误,我认为情况并非如此,因为当我在Chrome中加载它时,它会工作。然后你在加载包含getFullSpec()的js.file之前单击。我不知道完整的phantom api,但在加载所有页面js时,请尝试开发您的脚本。这里有一个类似的问题。我们在这篇文章中找到了正确的解决方案,所以看起来这一定是答案。我可以编辑它,但似乎不需要它。