在以下人员的帮助下,我有以下 jQuery 选择LGSon的回答 https://stackoverflow.com/a/51113888/1375163 to an 先前的问题 https://stackoverflow.com/questions/51113761/jquery-selector-to-ignore-an-element...
$('div.content__article-body > *').not('aside').each( function( index, value ) {
console.log( value.outerHTML );
});
但是,我需要学习如何以与result
下面是我的代码的一部分...
我想我需要链接outerHTML
element 到 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;
}