2013-06-30

AutoPagerizeを連番URLでも使えるようにする

page-1 page-2 page-3みたいなやつ

autopagerize incrementalでググるとそれっぽいのが出てくる

こんなかんじの記述Autopagerize適当場所に追加したら連番URLでも使えるようになるはず

var pages = getElementsByXPath(this.info.pageElement, htmlDoc);

var url = this.getNextURL(this.info.nextLink, htmlDoc);

if (this.info.incremental) {

var exp = new RegExp(this.info.incremental.nextMatch,'i');

var _m = this.info.incremental.nextLink;

var step = this.info.incremental.step || 1;

url = this.requestURL.replace(exp,function(m0,m1){

var n = parseInt(m1,10) + step;

return _m.split('#').join(n);

});

}

var next = getFirstElementByXPath(xpath, doc);

if (next) {

if (this.info.incremental) {

var loc = this.requestURL || location.href;

var exp = new RegExp(this.info.incremental.nextMatch,'i');

var nextLink = this.info.incremental.nextLink;

var step = this.info.incremental.step || 1;

if (loc.match(exp)) {

return loc.replace(exp,nextLink.replace("#",parseInt(RegExp.$1)+step));

} else if (!loc.match(exp)) {

return loc + nextLink.replace("#",step);

}

} else {

return next.getAttribute('href') || next.getAttribute('action') || next.getAttribute('value');

}

}

連番に適応するSITEINFOはこんなかんじになる

pageelementは普通のsiteinfoと同じ

nextlinkはリンクをたどるわけじゃないので意味ないのだが一応書いておく必要があるので'//a'とでも書いておけばいい

url: '^http://matome\.naver\.jp/odai/'

,incremental: {

nextMatch: 'page=(\\d+)'

,nextLink: 'page=#'

}

,pageElement: '//div[@role="main"]'

,nextLink: '//a'

サンプル

http://matome.naver.jp/odai/2135645268395674701

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん