Monday, November 4, 2013

Ruby: Mechanize get html body as string

Below ruby mechanize code will help you to retrieve the HTML content from the provide link.

agent = { |a|
a.user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'
a.follow_meta_refresh = true

page = $agent.get("")
content = page.body

Ruby mechanize is a very sophisticated library to perform lot of powerful task including mimicking the browser itself. You'll find lot of online tutorial regarding this issue.

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...