Methods to Submit a Form With POST Using {Curl | Perl | Python | Ruby | Lynx}
Assume that you have a form , in the source look for something similar to :
input name="rid" type="TEXT" input name="submit" value="SUBMIT" type="SUBMIT" align="center"
Then , based on your needs select any of the methods to POST the data to the form and get the required results back
Using curl : curl -s -d "rid=value%&submit=SUBMIT" > out.html
Using Lynx to dump data : curl -sd 'rid=1ap05cs013&submit=SUBMIT' | lynx -dump -nolist -stdin > out.html
Using Perl :
“
!/usr/bin/perl -w
use strict; use LWP::UserAgent; use warnings;
sub send_to {
my $browser = LWP::UserAgent->new;
my $response = $browser->post(
'URL',
[
'rid' => $rid,
'submit' => 'SUBMIT'
],
);
print ( $response->content );
}
Using Python :
“
!/usr/bin/env python
import urllib
URL to post to
url = ‘URL’ values = {‘rid’: rid,
'submit': 'SUBMIT'}
html = urllib.urlopen(url, urllib.urlencode(values)).read() print html
Using Ruby : require "uri" require "net/http" uri = URI.parse('URL') req = Net::HTTP::Post.new('URL')
req.set_form_data({ ‘rid’ => ‘value’,
‘submit’ => ‘SUBMIT’ }) res = Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) } File.open(‘out.htm’, ‘w’) { |f| f.write res.body }
About Hemanth HM
Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.