LoginSignup
2
0

More than 5 years have passed since last update.

ページ上の全てのリンクを正規表現で取得するブックマークレット

Posted at

できる事

ページのアンカータグのリンクとテキストを正規表現で絞り込んで取得します。取得できた物をエクセル等に貼り付けやすいように、別ウィンドウにテーブルで出力します。

使い方

以下の###your regular expresstion###
の所に正規表現を入れてください。

例えば
http://example.com/000/ 
のようなURLを取りたい場合は以下のようにすれば

match(/http:\/\/example.com\/[0-9]+\/$/)
となります。

javascript:(function(){
var%20d=window.document;
var%20as=d.getElementsByTagName("a");
var%20s="";
for(var%20i=0,len=as.length;i<len;i++){
if(as[i].href.match(/###your regular expresstion###/)){s+="<tr><td>"+as[i].innerText+"</td><td>"+as[i].href+"</td></tr>";}}
nwin=window.open("");
nwin.document.open();
nwin.document.write("<table>"+s+"</table>");
nwin.document.close();
d.body.appendChild(v);})();void(0);

バリエーション

テキストがないものは除く

as[i].innerText!=''を正規表現のマッチと併せてチェックする

javascript:(function(){
var%20d=window.document;
var%20as=d.getElementsByTagName("a");
var%20s="";
for(var%20i=0,len=as.length;i<len;i++){
if(as[i].href.match(/###your regular expresstion###/)%20&&%20as[i].innerText!=''){s+="<tr><td>"+as[i].innerText+"</td><td>"+as[i].href+"</td></tr>";}}
nwin=window.open("");
nwin.document.open();
nwin.document.write("<table>"+s+"</table>");
nwin.document.close();
d.body.appendChild(v);})();void(0);

カンマ区切りで出す

javascript:(function(){
var%20d=window.document;
var%20as=d.getElementsByTagName("a");
var%20s="";
for(var%20i=0,len=as.length;i<len;i++){
if(as[i].href.match(/###your regular expresstion###/)){s+=as[i].innerText+","+as[i].href+"<br />";}}
nwin=window.open("");
nwin.document.open();
nwin.document.write(s);
nwin.document.close();
d.body.appendChild(v);})();void(0);
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0