Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'sinatra'
  2. require 'hpricot'
  3. require 'open-uri'
  4.  
  5. set :server, 'webrick'
  6.  
  7. class Page
  8.   def initialize(link)
  9.     @link = "https://facebook.com/" + link
  10.     doc = Hpricot(open(@link))
  11.     @title = (doc/"title").inner_text
  12.   end
  13.  
  14.   def link
  15.     @link
  16.   end
  17.  
  18.   def title
  19.     @title
  20.   end
  21.  
  22. end
  23.  
  24.  
  25. get '/' do
  26.   str = File.read('source.html')
  27.   id = /\d{5,20}/
  28.  
  29.   @matches = str.scan id
  30.   @pages = []
  31.   @matches.each do |id|
  32.     @pages << Page.new(id)
  33.   end
  34.  
  35.   erb :index
  36.  
  37. end
  38.  
  39. #index.erb
  40. <% @pages.each do |page| %>
  41.  
  42.   <p> <a href=<%= page.link %>><%= page.link %></a> | <%= page.title %> </p>
  43. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement