3/31 にポストされた
「 base要素が使用されていると3ページ目のnextLinkの取得が失敗する件」
に該当する現象が下記URLで発生(再現?)ているので報告します
http://gihyo.jp/admin/serial/01/ubuntu-recipe
(当方の環境:Vista + Firefox 2.0.0.16 + AutoPagerize 0.0.31)
==現象==
スクロールダウンして継ぎ足しをしていくと、3ページ目のURL生成に失敗し
「指定されたページは,サイト内に見つかりませんでした。」
と表示され継ぎ足しに失敗します
使用したSITEINFO は
url :^http://gihyo\.jp/
nextLink :(//*[@class='next']//a)[1]
pageElement://div[starts-with(@class,"readingContent")]/*[not(starts-with(@class, "pageSwitch")) and not(@class="adBanner")]
==調査==
3ページ目のURL生成でおかしくなっています
生成されたURL:http://gihyo.jp/admin/serial/01/admin/serial/01/ubuntu-recipe?start=30
期待されたURL:http://gihyo.jp/admin/serial/01/ubuntu-recipe?start=30
admin/serial/01/ が2回繰り返されているのが間違いの特徴です
AutoPagerize のソースと変数の値を確認したところ、下記関数を2回目に呼び出した際に
間違ったURLが作成されていることがわかりました
AutoPager.prototype.getNextURL = function(xpath, doc) {
var next = getFirstElementByXPath(xpath, doc) <---- その一
if (next) {
var url = next.href || next.action || next.value <---- その二
if (!url.match(/^http:/)) {
url = pathToURL(url)
}
return url
}
}
「その一」での next 変数の中身(改行して整形しました)
<A href="admin/serial/01/ubuntu-recipe?start=30" target="_blank"> <!-- href属性に注目 -->
<IMG width="81"
height="13"
class="buttons"
alt="次のページへ"
src="http://gihyo.jp/assets/templates/gihyojp2007/image/image_link/pageSwitch_next.gif"
_base_href="http://gihyo.jp/"
/>
</A>
「その二」での各変数の中身
next.href : http://gihyo.jp/admin/serial/01/admin/serial/01/ubuntu-recipe?start=30
next.action: undefined
next.value : undefined
つまり「その一」---->「その二」の間に何か変なことが起こってるらしいのです
==解決?==
getAttribute href bug(http://www.glennjones.net/Post/809/getAttributehrefbug.htm)
等を参考にし、
next.href で絶対パスを取得するのをやめて、替わりに next.getAttribute('href', 2)
の相対パスを使うことで解決しました(pathToURL 関数内で絶対パスへ変換するようにした)
AutoPager.prototype.getNextURL = function(xpath, doc) {
var next = getFirstElementByXPath(xpath, doc)
if (next) {
var url = next.getAttribute('href', 2) || next.action || next.value //<----ここ変えた
if (!url.match(/^http:/)) {
url = pathToURL(url)
}
return url
}
}
==課題(誰かに頼みたい...)==
next.href の振る舞いが Firefox のバグなのか、ECMAScript の仕様なのか調べ切れてません
また、他OSや Firefox 1.5 系や 3.x 系での動作も未検証です(Opera等はもちろん...)
修正法に勘違いがあるかもしれません。情報提供や指摘お願いします。
以上、ご報告まで
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
k2jp