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

  • SEARCH
  • Home
  • 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 8685639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:37:48+00:00 2026-06-12T22:37:48+00:00

I found some solutions using post_connect_hook and pre_connect_hook , but it seems like they

  • 0

I found some solutions using post_connect_hook and pre_connect_hook, but it seems like they don’t work. I’m using the latest Mechanize version (2.1). There are no [:response] fields in the new version, and I don’t know where to get them in the new version.

  • https://gist.github.com/search?q=pre_connect_hooks
  • https://gist.github.com/search?q=post_connect_hooks

Is it possible to make Mechanize return a UTF8 encoded version, instead of having to convert it manually using iconv?

  • 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-12T22:37:49+00:00Added an answer on June 12, 2026 at 10:37 pm

    Since Mechanize 2.0, arguments of pre_connect_hooks() and post_connect_hooks() were changed.

    See the Mechanize documentation:

    pre_connect_hooks()

    A list of hooks to call before retrieving a response. Hooks are called with the agent, the URI, the response, and the response body.

     

    post_connect_hooks()

    A list of hooks to call after retrieving a response. Hooks are called with the agent, the URI, the response, and the response body.

    Now you can’t change the internal response-body value because an argument is not array. So, the next best way is to replace an internal parser with your own:

    class MyParser
      def self.parse(thing, url = nil, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_HTML, &block)
        # insert your conversion code here. For example:
        # thing = NKF.nkf("-wm0X", thing).sub(/Shift_JIS/,"utf-8") # you need to rewrite content charset if it exists.
        Nokogiri::HTML::Document.parse(thing, url, encoding, options, &block)
      end
    end
    
    agent = Mechanize.new
    agent.html_parser = MyParser
    page = agent.get('http://somewhere.com/')
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have been looking for some solutions but i have found nothing... Is
I've found some questions here about this topic, but none of the solutions solve
I found some classes designed for debugging in package com.sun.jdi like VirtualMachine , but
Although I have found some solutions to this problem, none of them refer to
I've searched the Internet and have found some good solutions for teeing STDOUT to
I have found some similar Que's on SO but had not find the solution.
I've search for some solution to my problem and I found this link .
I found some lovely websites - http://www.mini.jp/event_campaign/big-point/ , http://www.twenty8twelve.com/ and http://www.scozzese.com - all vertical
I found some problems when implementing Jake Wharton 's ViewPagerIndicator . These are what
I found some things I want to submit a pull request for in the

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.