Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行一个源';使用phantomJS创建javascript_Javascript_Phantomjs_Web Crawler - Fatal编程技术网

运行一个源';使用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

我想做以下工作:

  • 访问网站
  • 单击按钮=>javascript函数将更改部分html
  • 获取新更改的html的一些内容
  • 所有这些都是自动的

    我尝试了为nodejs提供的几种工具,包括和

    目前,我在PhantomJS中运行了这段代码

    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
      打开带有
      page.open()
      的链接时,它是否像浏览器一样加载每个文件(js、css…)

    • 如果有,我如何使用
      PhantomJS
      运行
      getFullSpec
      (包含在另一个
      js
      文件中)

  • Evelate方法中的Js将在第页执行, onclick listener中有一个错误
    您可以打开页面,打开devtools,在js源代码中搜索代码。

    感谢您的快速响应!你的意思是我可以使用PhantomJS来做这件事,但我的代码中有错误?你能告诉我如何修复它吗?这是页面js文件中的错误。我不知道如何修复,可能getFullSpec尚未初始化。所以在点击之前试着设置延迟。对不起,我不知道我是否理解正确。如果你的意思是源代码的javascript有错误,我认为情况并非如此,因为当我在Chrome中加载它时,它会工作。然后你在加载包含getFullSpec()的js.file之前单击。我不知道完整的phantom api,但在加载所有页面js时,请尝试开发您的脚本。这里有一个类似的问题。我们在这篇文章中找到了正确的解决方案,所以看起来这一定是答案。我可以编辑它,但似乎不需要它。