如何从Node JS中的HTML解析和读取数据

时间:2019-04-03 04:17:08

标签: javascript html node.js

我从请求中获得的html内容如下,

 <meta id="state" content="{&quot;config&quot;: {&quot;application_string_templates&quot;: {&quot;cta.button&quot;: &quot;Book Appointment&quot;, &quot;facet.insurance_plans.typeahead.placeholder&quot;: &quot;Choose Insurance Accepted&quot;, &quot;facet.languages.language.typeahead.placeholder&quot;: &quot;Choose Language&quot;, &quot;facet.location.placeholder&quot;: &quot;City, State (e.g. Atlanta, GA) or Zip&quot;, &quot;facet.name.accepting_new_patients&quot;: &quot;Accepting New Patients&quot;, &quot;facet.name.age_groups_seen.name&quot;: &quot;Age Groups Seen&quot;, &quot;facet.name.direct_book_capable&quot;: &quot;Book Online&quot;, &quot;facet.name.gender&quot;: &quot;Provider Gender&quot;, &quot;facet.name.insurance_plans&quot;: &quot;Insurance Accepted&quot;, &quot;facet.name.is_primary_care&quot;: &quot;Primary Care&quot;, &quot;facet.name.is_specialty_care&quot;: &quot;Specialty Care&quot;, &quot;facet.name.languages.language&quot;: &quot;Language&quot;}">

在这里,我想获取属性内容的数据。 这是我的代码,

function parseData(html){
 const {JSDOM} = jsdom;
 const dom = new JSDOM(html);
 const $ = (require('jquery'))(dom.window);
 //let's start extracting the data
 console.log($("#state"));
}

当我尝试通过id'state'获取它时,这是我得到的输出,

jQuery { '0': HTMLMetaElement {}, length: 1 }

任何人都可以请我帮忙。谢谢。

0 个答案:

没有答案