Grabbing web forms with Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grabbing web forms with Perl
# 1  
Old 12-19-2011
Grabbing web forms with Perl

Hello Everyone,
I've googled everywhere for this with no luck and my brain hurts.

I'm trying to write a program to take my webpages and search for forms.

I've used LWP::Simple to store a website in $content

I need to cut the form out of $content. I don't know how to do this seeing as how the form extends across multiple lines. Can anyone help me?

Beggining of form = <form
End of form = </form>

Any thoughts are appreciated. Thanks!
# 2  
Old 12-19-2011
You may try HTML::Form:

Code:
#!/usr/bin/perl

use warnings;
use strict;

use LWP::UserAgent; 
use HTML::Form; 
use Data::Dumper;

my $user_agent = LWP::UserAgent->new;
my $response = $user_agent->get( 'http://www.w3schools.com/html/html_forms.asp' );  
my @forms = HTML::Form->parse( $response );

print $_->dump for @forms;

The code produces:

Code:
zsh-4.3.14[t]% ./s  
GET http://www.google.com/search [searchform]
  sitesearch=www.w3schools.com   (hidden readonly)
  as_q=Search w3schools.com      (text)
  <NONAME>=Search                (submit)
GET http://www.w3schools.com/html/html_forms.asp
  firstname=                     (text)
  lastname=                      (text)
GET http://www.w3schools.com/html/html_forms.asp
  pwd=                           (password)
GET http://www.w3schools.com/html/html_forms.asp
  sex=<UNDEF>                    (radio)    [male/Male|female/Female]
GET http://www.w3schools.com/html/html_forms.asp
  vehicle=<UNDEF>                (checkbox) [*<UNDEF>/off|Bike/I have a bike]
  vehicle=<UNDEF>                (checkbox) [*<UNDEF>/off|Car/I have a car]
GET http://www.w3schools.com/html/html_form_action.asp [input0]
  user=                          (text)
  <NONAME>=Submit                (submit)

Check this blog post.
# 3  
Old 12-19-2011
I'll give this a shot. I appreciate the help.

---------- Post updated at 05:01 PM ---------- Previous update was at 04:57 PM ----------

Worked like a charm. Thanks so much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl text from web

perl -MLWP::Simple -le '$s=shift;$c=get("http://genetics.emory.edu/egl/tests/view.php?testid=4125/$s/");$c=~/meta content=(.*?)name=\"Genes\"/msg; print length($1),"\t$1"' "Test Description" >output.txt I am having trouble with this code: Can it be modified for the desired output? I attached... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Grabbing fields with perl

I have several .csv files containing data like this: field_1;field_2;date;comment;amount; I want to extract the 3 last fields and load them in a database. my input_file = "/dir/file.csv"; my output_file = "/dir/file.sql"; open my $csv_file, '<', $input_file or die "Can't... (1 Reply)
Discussion started by: freddie50
1 Replies

3. Shell Programming and Scripting

How to call perl web service from javascript?

Hi, I would like to call the below perl web service from javascript .Any help would be appreciated.I am new to web services.Please do the needful. Server Program(Perl Web Service) #!/usr/bin/perl use lib '/usr/lib/perl5/5.8.8/SOAP-Lite-0.65_3/lib'; use SOAP::Transport::HTTP; use Demo;... (3 Replies)
Discussion started by: liyakathali
3 Replies

4. Shell Programming and Scripting

Web Service in Perl CGI scripting

Hi, I have a requirement to write web service in Perl CGi scripting.The web service will be called by some external programs.Any help would be appreciated.Sample hello world program will be more helpful. Thanks, Liyakath Ali. (1 Reply)
Discussion started by: liyakathali
1 Replies

5. UNIX for Dummies Questions & Answers

Help on Perl web automation

Hi All, Could experts in the forum suggest me a good book to create web based applications using Perl. Much thanks in advance Karthick (2 Replies)
Discussion started by: karthickrn
2 Replies

6. UNIX for Dummies Questions & Answers

Downloading file from web using perl script

Hi experts, I've question in perl, i need to download a text file from the Web and save that content to the server, Is it possible in perl script or i need to do it in the excel. I tried in the excel but the alignment is missing there. Could you please help in find that. Thanks senthilkumar (0 Replies)
Discussion started by: senthil.ak
0 Replies

7. Shell Programming and Scripting

grabbing specific column perl

Alright, I'm new to Perl so be gentle. Given the following script: ---- open(file, "<file.txt"); @lines = <file>; close(file); $var = print $lines; ---- So I'm printing line 18 of the file "file.txt". I now want the 5th column, minus the forward slash. The line looks like this: ... (2 Replies)
Discussion started by: wxornot
2 Replies

8. Shell Programming and Scripting

How to call a web service using perl

Hello to all, What i would like to know is how to call a web service using perl. Where can i find documentation that easy describes this procedure? Any advices will be more tha welcome. Thank you. Best Regards, Chriss_58 (3 Replies)
Discussion started by: chriss_58
3 Replies

9. Shell Programming and Scripting

Perl CGI forms

Hello All, I am calling a script 'abc.pl' in my action section while creating a form. This will automatically pass parameters that are collected in the form. But I want to pass other parameters which are actually just variables in the script I am calling 'abc.pl' from. How do I make sure these... (4 Replies)
Discussion started by: garric
4 Replies

10. Shell Programming and Scripting

Web automation using perl

Hi all, I have to test a web application which has secure authorization. It is a ticketing site where I can create tickets,view and close them. I am trying to automate it in perl and I am not aware of how to do UI automation using perl. Please guide me in steps to implement a perl... (1 Reply)
Discussion started by: gurukottur
1 Replies
Login or Register to Ask a Question