preload

Sending a POST Request / Scrape Page in Ruby

Making a POST request in Ruby is simple. You can very easily load the data returned from the web service to parse or do whatever is necessary with it. This tutorial is the cornerstone for users who might be interested in developing their own web scraper in Ruby. 

First, make sure to require the appropriate Ruby libraries net/http and uri. Next we will utilize the post_form method from HTTP, using the websites URL and a hash comprised of the POST key/value that you want to send in. You can use multiple values in the hash if necessary.

Running the parse method from URI will automatically format the URL you pass to the post_form method for easy manipulation.

The value returned and placed into the postData variable is a string representation of the source returned after your post request. This is a simple solution to a question that web developers often have.

Leave a Reply

* Required
** Your Email is never shared