Created
October 22, 2014 13:15
-
-
Save matiasinsaurralde/0f89f527c1133cc1ef4e to your computer and use it in GitHub Desktop.
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
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