我正在获取网页的内容(使用nodejs的scipio模块)。从网页上,我需要提取表格{title:“...”......}的所有行。网页的相关部分如下所示:
//<!--
if(!ALEXA)
var ALEXA={viewsHelpers:{}};
if(!ALEXA.viewsHelpers.map)
ALEXA.viewsHelpers.map={};
ALEXA.viewsHelpers.map.div= "visitsMap";
ALEXA.viewsHelpers.map.areas=[
{title:"United States: 29.8%",id:"US",value:"5.39"},
{title:"India: 8.9%",id:"IN",value:"4.19"},
{title:"Russia: 3.3%",id:"RU",value:"3.19"},
{title:"Japan: 3.3%",id:"JP",value:"3.19"},
{title:"Brazil: 3%",id:"BR",value:"3.1"},
{title:"United Kingdom: 2.9%",id:"GB",value:"3.06"},
{title:"Iran: 2.5%",id:"IR",value:"2.92"},
{title:"France: 2.3%",id:"FR",value:"2.83"},
{title:"Spain: 2.3%",id:"ES",value:"2.83"},
{title:"Germany: 2.3%",id:"DE",value:"2.83"},
{title:"Mexico: 2.1%",id:"MX",value:"2.74"},
{title:"Italy: 2%",id:"IT",value:"2.69"},
{title:"Canada: 1.9%",id:"CA",value:"2.64"},
{title:"Indonesia: 1.7%",id:"ID",value:"2.53"},
{title:"Turkey: 1.2%",id:"TR",value:"2.18"},
{title:"Australia: 1.2%",id:"AU",value:"2.18"},
{title:"Pakistan: 1%",id:"PK",value:"2"},
{title:"Taiwan: 0.9%",id:"TW",value:"1.89"},
{title:"Argentina: 0.9%",id:"AR",value:"1.89"},
{title:"Netherlands: 0.9%",id:"NL",value:"1.89"},
{title:"South Korea: 0.9%",id:"KR",value:"1.89"},
{title:"Poland: 0.9%",id:"PL",value:"1.89"},
{title:"China: 0.8%",id:"CN",value:"1.78"},
{title:"Saudi Arabia: 0.8%",id:"SA",value:"1.78"},
{title:"Malaysia: 0.8%",id:"MY",value:"1.78"},
{title:"South Africa: 0.8%",id:"ZA",value:"1.78"},
{title:"Thailand: 0.7%",id:"TH",value:"1.64"},
{title:"Nigeria: 0.7%",id:"NG",value:"1.64"},
{title:"Colombia: 0.7%",id:"CO",value:"1.64"},
{title:"Egypt: 0.6%",id:"EG",value:"1.49"},
{title:"Ukraine: 0.6%",id:"UA",value:"1.49"},
{title:"Venezuela: 0.6%",id:"VE",value:"1.49"},
{title:"Philippines: 0.6%",id:"PH",value:"1.49"},
{title:"Singapore: 0.5%",id:"SG",value:"1.31"},
{title:"Greece: 0.5%",id:"GR",value:"1.31"}];
//-->
有关如何实现这一目标的任何建议都会有所帮助
答案 0 :(得分:0)
如果我理解你的问题,你可以做到
html = html.split('\n').filter(function(l){
return !/^\s*{title:.*},?\s*/.test(l)
}).join('\n');