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.
RightSignature
2 Comments
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…
hahahaha, thanks. That’s what I get for drinking too much coffee.