Skip to content

Instantly share code, notes, and snippets.

@matiasinsaurralde
Created October 22, 2014 13:15
Show Gist options
  • Save matiasinsaurralde/0f89f527c1133cc1ef4e to your computer and use it in GitHub Desktop.
Save matiasinsaurralde/0f89f527c1133cc1ef4e to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
def get_followers_from_page(url)
page, followers = Nokogiri::HTML(open(url).read()), []
user_items = page.xpath("//table[@class='user-item']")
user_items.each do |user_item|
nickname = user_item.xpath(".//a[@data-scribe-action='profile_click']/@href").first.to_s
nickname = nickname[1,nickname.size]
splits = nickname.split('?')
nickname = splits[0]
followers << nickname
end
p page.xpath("//div[@class='w-button-more']/a/@href").first.value
followers
end
def select_followers_from(nickname, n=10)
result = []
base_url = "https://mobile.twitter.com/#{nickname}/followers"
followers = get_followers_from_page(base_url)
n.times do
result << followers.sample
end
result
end
select_followers_from( 'xgurix', 1 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment