我正在使用pjscrape从一个站点生成的动态页面中抓取内容。请参阅下面的代码。我想不出我需要做什么才能让它打印出转储到文件的json变量中抓取的页面的url。我尝试过各种方法,包括document.url等(参见下面代码中注释掉的第3-6行)。但是,我不知道如何获取urlFound变量来获得正确的值。当然,答案可能非常简单,但我对此莫名其妙。还有别的办法吗?帮助!
var scraper = function() {
return {
//urlFound:$(window.location.href),
//urlFound: $(this).window.location.href,
//urlFound: _pjs.toFullUrl($(this).attr('href')),
//urlFound: _pjs.toFullUrl($(this).URL),
// Heck - how to print out the url being scraped???
name: $('h1').text(),
marin: _pjs.getText($("script:contains('marin')"))
}
};
pjs.config({
// options: 'stdout', 'file' (set in config.logFile) or 'none'
log: 'stdout',
// options: 'json' or 'csv'
format: 'json',
// options: 'stdout' or 'file' (set in config.outFile)
writer: 'file',
outFile: 'scrape_output.json'
});
pjs.addSuite({
url: 'http://www.mophie.com/index.html',
moreUrls: function() {
return _pjs.getAnchorUrls('li a');
},
scraper: scraper
});发布于 2013-11-08 05:41:39
在window.location.href上,您的选择器不需要jquery。不确定如何访问pjscraper的内部url,但更改代码如下所示:
var scraper = function() {
return {
urlFound: window.location.href,
name: $('h1').text(),
marin: _pjs.getText($("script:contains('marin')"))
}
};发布于 2014-10-09 03:20:40
或者,您可以使用document.URL...save将其作为变量,然后使用How to read and write into file using JavaScript将其写入文件
https://stackoverflow.com/questions/18051224
复制相似问题