-
-
Save andrewkolesnikov/4993238 to your computer and use it in GitHub Desktop.
Exports every wall post from vkontakte.ru to a CSV Updated in Feb 2013, Ruby 1.9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mechanize' | |
require 'fastercsv' | |
require 'progressbar' | |
cookie, gid = ARGV | |
url = URI.parse("http://vkontakte.ru/wall-#{gid}") | |
agent = Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
Mechanize::Cookie.parse(url, "remixsid=" + cookie) { |c| agent.cookie_jar.add(url, c) } | |
pages = agent.get(url.to_s).search('#fw_summary_wrap .pg_lnk:last').attr('href').value.split('=').last.to_i/20 | |
FasterCSV.open('export_vk_wall.csv','w') do |csv| | |
csv << ['name', 'message', 'time'] | |
(0...pages).to_a.each_with_progressbar('Progress') do |p| | |
url.query = "offset=#{p * 20}" | |
page = agent.get(url.to_s).search("#page_wall_posts") | |
page.search('.post .info').each do |post| | |
csv << [ | |
post.search('a.author').text, | |
post.search('.wall_text div div').text, | |
post.search('.rel_date').text | |
] | |
end | |
sleep(5 + rand(11)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment