Blog

Jun
25
Scraping Images from Twitpics
by Alex Chee | Snippet

Recently, I’ve been scraping Images and videos from Twitter and one site that has not been too easy to grab pics from is Twitpics. Here’s a snippet of code that I’ve been using to grab the image from Twitpic with Hpricot:


require 'net/http'
require 'hpricot'

def rip_twitpic(url)
begin
code=url.match(/[\w]+$/).to_s
unless code.blank?
uri=URI.parse(url)
resp=Net::HTTP.get_response(uri)
html=Hpricot(resp.body)
html.at("#photo-display")['src']
end
rescue Exception => e
puts "Error extracting twitpic: #{e}"
url
end
end

Note: Thanks to Stephen Boisvert for showing my typo. That’s what I get for rushing something out and drinking too many cups of coffee.

2 Comments
June 26, 2009

I hate to do this publicly but I couldn’t find a private channel to contact you.

Scrapping : To break down into parts for disposal or salvage.
Scraping: Something scraped off; that which is separated from a substance, or is collected by scraping; as, the scraping of the street.

Thought you might like to know so you can fix it…

June 26, 2009

hahahaha, thanks. That’s what I get for drinking too much coffee.