I'm trying to use Mechanize to scape some tags from a page. I've used Nokogiri successfully to scrape them before, but now I'm trying to combine them into a wider Mechanize class. Here is the Nokogiri statement:
page = Nokogiri::HTML(open(@model.url, "User-Agent" => request.env['HTTP_USER_AGENT']))
@model.icons = page.css("link[rel='apple-touch-icon']").to_s
And here is what I thought would be the Mechanize equivalent but it's not working:
agent = Mechanize.new
page = agent.get(@model.url, "User-Agent" => request.env['HTTP_USER_AGENT'])
@model.icons = page.search("link[rel='apple-touch-icon']").to_s
The first one returns a link tag as expected <link rel="apple-touch-icon" etc etc..></link>
. The second statement returns a blank string. If I take the to_s
off the end I get a super long output. I assume it's an error or the actual Mechanize object or something.
Link to long output when not converting to string: https://gist.github.com/eadam/5583541