SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'rubygems'
  2. require 'mechanize'
  3. require 'uri'
  4. require 'nokogiri'
  5.  
  6.  
  7. def get_group_posts(group_id,limit)
  8.     out = []
  9.     client = Mechanize.new
  10.  
  11.     url_grp = URI::HTTPS.build(host: 'ok.ru',path: "/group#{group_id}")
  12.     body = client.get(url_grp).body
  13.     body =~ /st.markerb="(.+?)"/i
  14.     markerB = $1
  15.     body =~ /gwtHash:"(.+?)"/i
  16.     gwt_requested = $1
  17.  
  18.     html_requests_page = Nokogiri::HTML.fragment(body)
  19.     puts "1 feed page(#{markerB})"
  20.     out =+ html_requests_page.search(".feed-w")
  21.  
  22.     start_page = 2
  23.  
  24.     url = URI::HTTPS.build(host: 'ok.ru',path: '/dk', query: URI.encode_www_form(
  25.       'cmd': 'AltGroupMainFeedsNewRB',
  26.       'st.gid': group_id
  27.     ))
  28.      []
  29.  
  30.     while markerB && out.count < limit do
  31.         puts "#{start_page} feed page(#{markerB})"
  32.         content = client.post(url,{
  33.             'fetch': false,
  34.             'st.page': start_page,
  35.             'st.markerB': markerB,
  36.             'gwt.requested': gwt_requested
  37.         }).body
  38.         content =~ /st.markerb="(.+?)"/i
  39.         markerB = $1
  40.         ajax_requested_page = Nokogiri::HTML.fragment(content)
  41.  
  42.         posts = ajax_requested_page.search(".feed-w") #это прост для примера
  43.  
  44.         out += posts
  45.  
  46.         start_page += 1
  47.        
  48.     end
  49.    
  50.     #вот туть надо сделать чтобы если на странице больше постов чем надо до лимита последнии из out выпиливать
  51.     out
  52. end
  53.  
  54. get_group_posts('53485850722549',40)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top