Created
November 14, 2012 22:55
-
-
Save ascheink/4075439 to your computer and use it in GitHub Desktop.
HuffPost 100 most recent links for tag
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 'rubygems' | |
require 'nokogiri' | |
require 'httparty' | |
def scrape(tag) | |
links = [] | |
(1..4).each do |n| | |
new_links = scrape_tag_page "http://www.huffingtonpost.com/tag/#{tag}/#{n}" | |
break if new_links.empty? | |
links += new_links | |
end | |
links | |
end | |
def scrape_tag_page(tag_page_url) | |
response = HTTParty.get tag_page_url | |
page = Nokogiri::HTML(response) | |
page.css('.entry h3 a').map { |link| link['href'] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment