LoginSignup
6
5

More than 5 years have passed since last update.

URLを引っこ抜くやつ

Posted at

昔、はるか昔、チョメチョメな画像を集めるときに重要なテクニックでした。
wgetやcurlは自主規制にしています。

lynx

lynxでナイス。

$ lynx --dump http://b.hatena.ne.jp | awk '$2 ~/^http/ { print $2 }'

rubyでOK!
相対パス絶対パスは気にしないと短いね。

Nokogiri::HTML(open('http://b.hatena.ne.jp')).css('a').each {|link|
  puts link.attr(:href)
}

ここではベンチは重要ではないけど一応。

$ time lynx --dump http://b.hatena.ne.jp | awk '$2 ~/^http/ { print $2 }' > /dev/null

real    0m0.145s
user    0m0.050s
sys     0m0.026s

$ time ./get_urls.rb > /dev/null

real    0m0.359s
user    0m0.223s
sys     0m0.052s

6
5
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
6
5