Phantomjs 如何让pjscrape打印出文件中的当前url?
我使用PJScrae从站点生成的动态页面中获取内容。请参阅下面的代码。 我不知道我需要做什么才能让它在转储到文件中的json变量中打印出刮取页面的url。我尝试过各种方法——包括document.url等(参见下面代码中注释掉的第3-6行)。但是,我不知道如何获取urlFound变量以获得正确的值。当然,答案可能非常简单,但我无法回答。还有别的办法吗?救命啊Phantomjs 如何让pjscrape打印出文件中的当前url?,phantomjs,Phantomjs,我使用PJScrae从站点生成的动态页面中获取内容。请参阅下面的代码。 我不知道我需要做什么才能让它在转储到文件中的json变量中打印出刮取页面的url。我尝试过各种方法——包括document.url等(参见下面代码中注释掉的第3-6行)。但是,我不知道如何获取urlFound变量以获得正确的值。当然,答案可能非常简单,但我无法回答。还有别的办法吗?救命啊 var scraper = function() { return { //urlFound:$(window.location.
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
});
在
window.location.href
上,您的选择器不需要jquery
。不确定如何访问pjscraper
的内部url,但将代码更改为以下方式可以:
var scraper = function() {
return {
urlFound: window.location.href,
name: $('h1').text(),
marin: _pjs.getText($("script:contains('marin')"))
}
};
或者您可以使用
document.URL
…将其保存为变量,然后使用