Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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 解析HTML结构,有哪些JS工具可用_Javascript_Html_Node.js_Html Parsing - Fatal编程技术网

Javascript 解析HTML结构,有哪些JS工具可用

Javascript 解析HTML结构,有哪些JS工具可用,javascript,html,node.js,html-parsing,Javascript,Html,Node.js,Html Parsing,我必须从网站的HTML表格中获取信息。我想从Node.ja服务器向该网站发出一个HTML请求,并解析HTML表。除了正则表达式之外,JS是否还有其他库或技术来解析表单元格中的数据 对不起,我是编程新手。我会使用JQuery。您可以像这样遍历所有表数据:(这将提醒每个表数据中的html) 或针对特定表格: $('#specific_table_id.td').each( function () { alert( $(this).html() } ); 您可以使用诸如getElementByTag

我必须从网站的HTML表格中获取信息。我想从Node.ja服务器向该网站发出一个HTML请求,并解析HTML表。除了正则表达式之外,JS是否还有其他库或技术来解析表单元格中的数据


对不起,我是编程新手。

我会使用JQuery。您可以像这样遍历所有表数据:(这将提醒每个表数据中的html)

或针对特定表格:

$('#specific_table_id.td').each( function () { alert( $(this).html() } );
您可以使用诸如getElementByTagName、firstChild等普通DOM函数从下载的HTML页面获取实际数据


请参阅更多方法。

查看优秀的Cheerio库:


示例在Git上。

jsdom是一个很好的模块

// Count all of the links from the Node.js build page
var jsdom = require("jsdom");

jsdom.env(
  "http://nodejs.org/dist/",
  ["http://code.jquery.com/jquery.js"],
  function (errors, window) {
    console.log("there have been", window.$("a").length, "nodejs releases!");
  }
);

有一些方法可以在node.js上加载jQuery,但大多数方法都依赖于DOM仿真,并且并不总是与所有jQuery插件兼容。
var doc = document.implementation.createDocument(null, your_downloaded_html_page_as_string, null);
// Count all of the links from the Node.js build page
var jsdom = require("jsdom");

jsdom.env(
  "http://nodejs.org/dist/",
  ["http://code.jquery.com/jquery.js"],
  function (errors, window) {
    console.log("there have been", window.$("a").length, "nodejs releases!");
  }
);