私はCasperJS でリンクスクレーパーを構築しています。主な機能は次のようになります。
function findLinks() {
return Array.prototype.map.call(document.querySelectorAll('a'), function(e){
return {
href: e.href,
title: e.title,
rel: e.rel,
anchor: e.text,
innerHTML: e.innerHTML
};
});
}
findLinks()
ただし、リンクスクレーパーが次のようなものを見つけた場合は、次のように変更したいと思います。
<a href="#" title="anchor tag" rel="nofollow"><img src="myimage.jpg" alt="beautiful image" /></a>
<img>
リンクの場合と同じように、属性に個別にアクセスできます。
私は Mozilla MDN と CasperJS を読んでいますが、これを達成する方法をまだ見つけていません。
どんな助けでも大歓迎です!