Severin
Severin

Reputation: 8588

Parse Faraday Response body as Nokogiri Object

I have considered switching from Mechanize to Faraday, since I am making a lot of requests and it seems to be a lot quicker. What I couldn't find out, however, is if it is possible to parse the response body as an Nokogiri Object. The Mechanize way to do so is as follows:

Mechanize.new.get(url).parser

How can that be achieved using Faraday instead of Mechanize?

Upvotes: 1

Views: 2020

Answers (1)

Severin
Severin

Reputation: 8588

The same result can be achieved by doing:

site = Faraday.new.get('http://www.mysite.com').body
nokogiri_object = Nokogiri::HTML(site)

Upvotes: 3

Related Questions