Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/easy-google-syntax-highlighter/easy-google-syntax-highlighter.php on line 50

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/easy-google-syntax-highlighter/easy-google-syntax-highlighter.php on line 50

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 305

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 305

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 306

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 306

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 307

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 307

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 308

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 308

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 309

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 309

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 310

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 310

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 311

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 311

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 312

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 312

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 316

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 316

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 317

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 317

Warning: Cannot modify header information - headers already sent by (output started at /home/umeshw/techfeedlab.com/wp-content/plugins/easy-google-syntax-highlighter/easy-google-syntax-highlighter.php:50) in /home/umeshw/techfeedlab.com/wp-content/plugins/wp-greet-box/includes/wp-greet-box.class.php on line 493
Ruby | Technology Feed Lab

Technology Feed Lab

technology site

Archive for the ‘Ruby’ Category

How to fetch webpage using Ruby and Mechanize

Posted by TechGeek on June 30, 2011

Few days back, we learned on how to fetch a webpage using Perl and Mechanize. This simple article explains how to fetch a webpage using Ruby and Mechanize. Ruby is yet another powerful programming language. It is an object-oriented programming language inspired by Perl. The syntax is very easy to understand and you can do lot more things with this language. If you want to learn Ruby you should download the Ruby installer here. Anyways, the code will be very similar as we seen in the earlier blog.

You will need to install the Mechanize first. You can do it by running Gem command like ‘gem install mechanize’. The Ruby uses ‘require’ to add and use that module. Here is very simple code to get you started,
——————————–-------------
#!/usr/bin/ruby

require 'mechanize'

agent = Mechanize.new
puts "Fetching webpage"

res = agent.get( 'http://www.google.com')

data = res.body

#Play with response data
puts data

—————————————————-

Once you will fetch the webpage, you can do anything you want using Ruby regular expressions. You can find all methods and examples on “http://mechanize.rubyforge.org/” website. This is very simple example for beginners. Hope this will be useful.

pixel How to fetch webpage using Ruby and Mechanize

Posted in How-To, Ruby, Technology | Tagged: , , | Leave a Comment »