Scraping Images from Twitpics

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

  1. Posted June 26, 2009 at 10:13 am | Permalink

    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…

  2. Posted June 26, 2009 at 5:41 pm | Permalink

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">