我有以下jquery选择,有以下帮助
LGSon's answer
对
earlier question
…
$('div.content__article-body > *').not('aside').each( function( index, value ) {
console.log( value.outerHTML );
});
但是,我需要学习如何以符合
result
下面是我的部分代码…
我想我需要把
outerHTML
元素到jquery行,但我在这方面没有取得太多成功。
在本例中,选择用于
"entry"
.
function pageFunction(context) {
// Called on every page the crawler visits, use it to extract data from it
var $ = context.jQuery;
// If page is START or a LIST,
if (context.request.label === 'START' || context.request.label === 'LIST') {
context.skipOutput();
// First, gather LIST page
$('ol.pagination li a').each(function() {
context.enqueuePage({
url: window.location.origin + $(this).attr('href'),
label: 'LIST'
});
});
// Then, gather every DETAIL page
$('h3>a').each(function(){
context.enqueuePage({
url: window.location.origin + $(this).attr('href'),
label: 'DETAIL'
});
});
// If page is actually a DETAIL target page
} else if (context.request.label === 'DETAIL') {
/* context.skipLinks(); */
var tags = [];
$('span.tags a').each( function() {
tags.push($(this).text());
});
result = {
"title": $('h1.entry-title').text(),
"excerpt": $('div.content-blog__body p strong:first').text().trim(),
"entry": $('div.content-blog__body').html().trim(),
"datestamp": $('meta[property="article:published_time"]').attr('content'),
tags: tags
};
}
return result;
}