Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.89 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env ruby
  2. require 'rubygems'
  3. require 'mechanize'
  4. require 'fastercsv'
  5. require 'progressbar'
  6.  
  7. cookie, gid = ARGV
  8. url = URI.parse("http://vkontakte.ru/wall-#{gid}")
  9.  
  10. agent = Mechanize.new
  11. agent.user_agent_alias = 'Mac Safari'
  12. Mechanize::Cookie.parse(url, "remixsid=" + cookie) { |c| agent.cookie_jar.add(url, c) }
  13. pages = agent.get(url.to_s).search('#fw_summary_wrap .pg_lnk:last').attr('href').value.split('=').last.to_i/20
  14.  
  15. FasterCSV.open('export_vk_wall.csv','w') do |csv|
  16.   csv << ['name', 'message', 'time']
  17.   (0...pages).to_a.each_with_progressbar('Progress') do |p|
  18.     url.query = "offset=#{p * 20}"
  19.     page = agent.get(url.to_s).search("#page_wall_posts")
  20.     page.search('.post .info').each do |post|
  21.       csv << [
  22.         post.search('a.author').text,
  23.         post.search('.wall_text div div').text,
  24.         post.search('.rel_date').text
  25.       ]
  26.     end
  27.     sleep(5 + rand(11))
  28.   end
  29. end