Skip to content

Instantly share code, notes, and snippets.

@gong023
Last active December 24, 2015 09:59
Show Gist options
  • Save gong023/6781036 to your computer and use it in GitHub Desktop.
Save gong023/6781036 to your computer and use it in GitHub Desktop.
fix nicnonico login fix ranking parsing
diff --git a/lib/niconico.rb b/lib/niconico.rb
index da773f9..d9f8940 100644
--- a/lib/niconico.rb
+++ b/lib/niconico.rb
@@ -22,6 +22,7 @@ class Niconico
@logined = false
@agent = Mechanize.new
+ @agent.ssl_version = "SSLv3"
end
def login(force=false)
diff --git a/lib/niconico/ranking.rb b/lib/niconico/ranking.rb
index 25c83e1..1a1ee6d 100644
--- a/lib/niconico/ranking.rb
+++ b/lib/niconico/ranking.rb
@@ -22,8 +22,13 @@ class Niconico
method = :fav if method == :all
page = @agent.get(url = "http://www.nicovideo.jp/ranking/#{method}/#{span}/#{category}")
- page.search("a.watch").map do |link|
- Video.new(self, link['href'].sub(/^.*?watch\//,""), title: link.inner_text)
+ kuso_arr = []
+ page.search("p.itemTitle.ranking").each do |link|
+ link.children.search("a").each do |elem|
+ matches = elem.attributes["href"].value.match(/(?<category>^.*?watch\/)(?<video_id>[a-z]+\d+)/)
+ kuso_arr << Video.new(self, matches["video_id"], title: elem.attributes["title"].value)
+ end
end
+ kuso_arr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment