Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:51:58+00:00 2026-06-10T00:51:58+00:00

I am using Net::HTTP for HTTP requests and getting a response back: uri =

  • 0

I am using Net::HTTP for HTTP requests and getting a response back:

uri = URI("http://www.example.com")
http = Net::HTTP.start(uri.host, uri.port, proxy_host, proxy_port)
request = Net::HTTP::Get.new uri.request_uri
response = http.request request # Net::HTTPResponse object
body = response.body

If I have to use the Nokogiri gem in order to parse this HTML response I will do:

nokogiri_obj = Nokogiri::HTML(body)

But if I want to use Mechanize gem I need to do this:

agent = Mechanize.new
mechanize_obj = agent.get("http://www.example.com")

Is it possible for me to use Net::Http for getting the HTML response and then use the Mechanize gem to convert it into a Mechanize object instead of using agent.get()?


EDIT:

The reason for getting around the agent.get() method is because I am trying to use EventMachine::Iterator to make concurrent EM-HTTP requests.

EventMachine.run do
  EM::Iterator.new(urls, 3).each do |url,iter|
    puts "giving   #{url}   to httprequest now"
    http = EM::HttpRequest.new(url).get
    http.callback { |resp|
      uri = resp.send(:URI, url)
      puts "inside callback of #{url}"
      body = resp.response
      page = agent.parse(uri, resp, body)
    }
    iter.next
  end
end

But its not working. I am getting an error:

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.5.1/lib/mechanize.rb:1165:in`parse': undefined method `[]' for #<EventMachine::HttpClient:0x0000001c18eb30> (NoMethodError)

when I use the parse method for Net::HTTP it works fine and I get the Mechanize object:

 uri = URI("http://www.example.com")
 http = Net::HTTP.start(uri.host, uri.port, proxy_host, proxy_port)
 request = Net::HTTP::Get.new uri.request_uri
 response = http.request request # Net::HTTPResponse object
 body = response.body
 agent = Mechanize.new
 page = agent.parse(uri, response, body)     

Am I passing the wrong arguments for the parse method while using em-http?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:51:59+00:00Added an answer on June 10, 2026 at 12:51 am

    I’m not sure why you think using Net::HTTP would be better. Mechanize will handle redirects and cookies, plus provides ready access to Nokogiri’s parsed document.

    require 'mechanize'
    
    agent = Mechanize.new
    page = agent.get('http://www.example.com')
    
    # Use Nokogiri to find the content of the <h1> tag...
    puts page.at('h1').content # => "Example Domains"
    

    Note, setting the user_agent isn’t necessary to reach example.com.


    If you want to use a threaded engine to retrieve pages, take a look at Typhoeous and Hydra.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The php.net page here http://www.php.net/manual/en/mysqlinfo.library.choosing.php says this Configure commands for using mysqlnd // Recommended,
In trying to implement the Twitter code at http://www.voiceoftech.com/swhitley/?p=681 I am getting a compile
I am using the kalitte toolkit from http://dynamicdashboards.net/ and we are having a request
I'm using .NET 3.5 SP1 in ASP.NET MVC application. While using ObjectContext with Http
I'm using http://datatables.net/examples/ for easy control table. I'm generating table with more than 30,000
I'm attempting to consume a HTTP Basic Auth Secured PHP WebService using VB.NET. I've
I've used the exact files from this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ The ideea is to submit
Using a data table from http://datatables.net/ , How can i stop it from overflowing
I am using the following plugin: http://codecanyon.net/item/dynamic-step-process-panels/118950 and I am trying to modify its
I'm using HTML Tidy Online ( http://infohound.net/tidy/ ) to tidy up some very old

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.