Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Last active September 13, 2019 04:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki0000/49d4ffdb5bca3cedeedd to your computer and use it in GitHub Desktop.
Save hyuki0000/49d4ffdb5bca3cedeedd to your computer and use it in GitHub Desktop.
note-prevs - note.mu の指定されたURLからprevリンクをたどり、各ページのタイトルとURLを表示するRubyスクリプト。
#!/usr/bin/env ruby
if ARGV.length != 1
puts "Usage: ruby note-prevs.rb https://note.mu/USERNAME/n/NOTEID"
puts "Example: ruby note-prevs.rb https://note.mu/hyuki/n/n220bad7464fb"
puts "This program visits given user's pages via prev-link and puts their titles and urls."
abort
end
# cf. https://note.mu/wadako/n/n01733b19bc9c
HEADER = %Q("user-agent:Mozilla/5.0(compatible;Googlebot/2.1;+http://www.google.com/bot.html)")
TMPFILE = "tmp.html"
url = ARGV[0]
loop do
system("curl --silent --header #{HEADER} \"#{url}?_escaped_fragment_=\" > #{TMPFILE}")
title = `grep --regexp \"<title>\" #{TMPFILE}`
if title.match("<title>(.*)</title>")
puts $1
else
puts "(title not found)"
end
puts url
line = `grep --regexp \"prev_note.*href\" #{TMPFILE}`
if line.match(/href=\"(.*)\"/)
url = "https://note.mu#{$1}"
else
break
end
sleep 1
end
@hyuki0000
Copy link
Author

$ ruby note-prevs.rb https://note.mu/hyuki/n/n220bad7464fb
書かない時間(文章を書く心がけ)|結城浩|note
https://note.mu/hyuki/n/n220bad7464fb
今日の振り返り|結城浩|note
https://note.mu/hyuki/n/nf3e9c596f3a1
結城さんがTwitterで行っていた「添削」を解説してもらえませんか?(Q&A)|結城浩|note
https://note.mu/hyuki/n/n73dd703922ac
信頼関係がすべての基礎(教えるときの心がけ)|結城浩|note
https://note.mu/hyuki/n/n3d6ee25a7dcd
さびしさということ(思い出の日記)|結城浩|note
https://note.mu/hyuki/n/nb27bbde0bc81
書籍の品質を向上させる「読み合わせ」の進め方(本を書く心がけ)|結城浩|note
https://note.mu/hyuki/n/n24cc7c12d4f5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment