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 7413915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:58:32+00:00 2026-05-29T06:58:32+00:00

I use mechanize gem to crawl websites. I wrote a very simple, one-threaded crawler

  • 0

I use mechanize gem to crawl websites. I wrote a very simple, one-threaded crawler inside a Rails rake task because I needed to access to Rails models.

The crawler runs just fine, but after watching it running for a while I can see that it eats more and more RAM over time, which is bad.

I use God gem to monitor my crawler.

Below is my rake task code, I’m wondering if it exposes any chance of memory leaking?

task :abc => :environment do
  prefix_url = 'http://example.com/abc-'
  postfix_url = '.html'
  from_page_id = (AppConfig.last_crawled_id || 1) + 1
  to_page_id = 100000

  agent = Mechanize.new
  agent.user_agent_alias = 'Mac Safari'

  (from_page_id..to_page_id).each do |i|
    url = "#{prefix_url}#{i}#{postfix_url}"
    puts "#{Time.now} - Crawl #{url}"
    page = agent.get(url)

    page.search('#content > ul').each do |s|
      var = s.css('li')[0].text()
      value = s.css('li')[1].text()
      MyModel.create :var => var, :value => value
    end

    AppConfig.last_crawled_id = i
  end
  # Finish crawling, let's stop
  `god stop crawl_abc`
end
  • 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-05-29T06:58:33+00:00Added an answer on May 29, 2026 at 6:58 am

    Unless you’ve got the very latest version of mechanize (2.1.1 was released only a day or so ago) by default mechanize operates with an unlimited history size, ie it keeps all the pages you visited and so will gradually use more and more memory.

    In your case there isn’t any point to this, so calling max_history= on your agent should limit how much memory is used in this fashion

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

Sidebar

Related Questions

I'm trying to use mechanize to perform a simple search on my college's class
I am attempting to use mechanize to veiw and collect data from various websites.
Why can't bundler locate the Mechanize gem? The following is in my Rails project's
I am building a crawler, I know how to use ruby mechanize to read
These are the modules I have installed. use WWW::Mechanize; use XML::Simple; use LWP::Simple; use
In ruby, if you use mechanize following 301/302 redirects like this require 'mechanize' m
I'm trying to use WWW::Mechanize to extract some links from the HTML page using
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
I have two scripts which use Mechanize to fetch a Google index page. I
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( $url ); say $mech->text; How could I

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.