我需要解析一个模板的html页面。我假设匹配被加载到一个数组中。然后我需要输出数组的内容。
var adBookmarkletData=[
'
MYSA Yahoo! APT Debugger',
'URL: '+document.location.href+'
',
'Pub ID: '+window.yld_mgr.pub_id+'
',
'Site Name: '+window.yld_mgr.site_name+'
',
'Content Topic ID List: '+window.yld_mgr.content_topic_id_list+'
',
'Site Section Name List: '+window.yld_mgr.site_section_name_list+'
'
];
for(i in window.yld_mgr.slots){
adBookmarkletData.push('Ad: ('+i+')Category:('+window.yld_mgr.slots[i].cstm_content_cat_list+')
');
};
//Here my problem starts
var myRegExp = new RegExp("place_ad_here\('(.*?)'\)");
//Here my Problem ends
adBookmarkletData.push(myRegExp.exec(document.innerHTML));
adBookmarkletData.push('
function createAptDebugger(){
for (i in adBookmarkletData){
document.write(adBookmarkletData[i]);
}
};
void(createAptDebugger());
RegEx模式适用于针对示例代码的在线测试程序。但是这里的结果是空的。我不知道如何将RegEx指向html页面,然后从数组中输出。
为了清晰起见,html在body中会有这样的标签。
结果如下所示:
place_ad_here('A728')
place_ad_here('ASPON120')
place_ad_here('ROLLOVER')
place_ad_here('A300')
place_ad_here('Middle1')
place_ad_here('B300')这几乎是我想要显示它们的方式。
提前致谢...