Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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
Javascript 获取parse.com CloudCode的html源代码w/XMLHttpRequest.js_Javascript_Node.js_Xml Parsing_Xmlhttprequest_Parse Platform - Fatal编程技术网

Javascript 获取parse.com CloudCode的html源代码w/XMLHttpRequest.js

Javascript 获取parse.com CloudCode的html源代码w/XMLHttpRequest.js,javascript,node.js,xml-parsing,xmlhttprequest,parse-platform,Javascript,Node.js,Xml Parsing,Xmlhttprequest,Parse Platform,对于云代码(parse.com),我试图从另一个网站上抓取web数据,但我无法以字符串形式获取网站的源代码 我试着使用这个模块 但是,当我尝试运行代码时,出现了错误Module child\u process.js not found 我假设它引用了XMLHttpRequest.js文件中的这一行 var spawn = require("child_process").spawn 但是,我在下载的文件夹中找不到要添加到目录中的child_process.js 是否有方

对于云代码(parse.com),我试图从另一个网站上抓取web数据,但我无法以字符串形式获取网站的源代码

我试着使用这个模块

但是,当我尝试运行代码时,出现了错误
Module child\u process.js not found

我假设它引用了XMLHttpRequest.js文件中的这一行

  var spawn = require("child_process").spawn
但是,我在下载的文件夹中找不到要添加到目录中的
child_process.js

是否有方法包含此文件,或者有更好的方法获取源代码

编辑:使用httpRequest云函数

Parse.Cloud.define("pushFavorites", function(request, response) {

    var xpath = require("cloud/xpath.js"), dom = require("cloud/dom-parser.js").DOMParser;          
    var doc;

    Parse.Cloud.httpRequest({
     
       url: "website.com",
       success: function(httpResponse) {
           doc = new dom().parseFromString(httpResponse.text);
        },
      error: function(httpResponse) {
          console.error('Request failed with response code ' + httpResponse.status);
   }
});

    var cells = xpath.select("//td[starts-with(@class, 'menugridcell')]", doc);

//etc...
在声明
cells
变量的行中,我得到了一个错误:
无法读取未定义的属性“nodeType”


使用console.log,
httpResponse.text
将源代码正确显示为字符串。我不确定错误是与httpResponse还是我的xpath有关。我能够使xpath.select()函数对其他一些手动设计的xml字符串正常工作。

解析云代码没有运行node,因此虽然您可以让一些模块工作,但并非所有模块都工作。在这种情况下,我怀疑您是否能够这样做,因为child_进程是一个核心节点模块(请参阅),所以在云代码中不可用


试着改用能满足您需求的工具。

投票结果接近可能是因为这个问题确实需要一个图书馆/资源来解决这个问题。更好的形式是选择一个解决方案,并在您尝试使用它时在此处获得编程帮助。您可能希望添加node.js标记。我现在遇到一个新错误,我在问题中添加了更多信息。我无法在解析时使用dom解析器或xpath,但您至少有一个异步问题。httpRequest是非阻塞的,因此
xpath.select()
调用在成功回调中初始化doc之前发生。尝试将所有代码移到回调中,看看这是否能让您更接近回调。
Parse.Cloud.define("pushFavorites", function(request, response) {

    var xpath = require("cloud/xpath.js"), dom = require("cloud/dom-parser.js").DOMParser;          
    var doc;

    Parse.Cloud.httpRequest({
     
       url: "website.com",
       success: function(httpResponse) {
           doc = new dom().parseFromString(httpResponse.text);
        },
      error: function(httpResponse) {
          console.error('Request failed with response code ' + httpResponse.status);
   }
});

    var cells = xpath.select("//td[starts-with(@class, 'menugridcell')]", doc);

//etc...