[Perl] Redirection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Perl] Redirection
# 1  
Old 09-02-2011
[Perl] Redirection

At the moment I have the following code which visits the site then saves the page:

Code:
$req = HTTP::Request->new(POST => $url . '/search.php');
$data = $ua->request($req)->decoded_content;
open(HTMLfile, '>hello.html'); print HTMLfile $data; close(HTMLfile);

From the page it saves theres a URL, what I wanted it to do was click through that URL because the redirecting is broken and save that page instead, but if thats harder to do I wouldn't mind it using a regex to grab that URL on the page and saving the content in the other URL:

Code:
<a href="http://website.com/search.php?searchid=10876" class="textcontrol">Click here if your browser does not automatically redirect you.

Thanks.

Last edited by AndrewTwain; 09-02-2011 at 01:49 PM..
# 2  
Old 09-02-2011
To grab the URL to another variable try this:
Code:
$data=~/http:\/\/[^"]+/;
$new_url=$&;

# 3  
Old 09-02-2011
The same:
Code:
perl -e '                                                                    
$data=q|<a href="http://website.com/search.php?searchid=10876" class="textcontrol">Click here if your browser does not automatically redirect you.|;
$data =~ m|http://.*com/search.php\?searchid=\d+|;
die "could not get the new url\n" unless $&;
$new_url = $&;
print "$new_url\n"; 
'


Last edited by yazu; 09-02-2011 at 01:28 PM.. Reason: The same.
# 4  
Old 09-02-2011
Bartus regex retrieved wrong URL and yazu no url was extracted.
# 5  
Old 09-02-2011
Don't know why.
Code:
% perl -e '
$data=q|<a href="http://website.com/search.php?searchid=10876" class="textcontrol">Click here if your browser does not automatically redirect you.|;
$data =~ m|http://.*com/search.php\?searchid=\d+|;
die "could not get the new url\n" unless $&;
$new_url = $&;
print "$new_url\n";
'
http://website.com/search.php?searchid=10876

# 6  
Old 09-02-2011
Try:
Code:
$data=~/(http:\/\/[^"]+)[^>]+>Click here if your browser does not automatically redirect you/;
$new_url=$1;

This User Gave Thanks to bartus11 For This Post:
# 7  
Old 09-02-2011
nevermind

Last edited by AndrewTwain; 09-02-2011 at 02:42 PM.. Reason: nvm
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

2. Shell Programming and Scripting

Redirection

Hello All, I am using the below script to gather various tools running by the user, we have more than 100 tools running on the server so my challenge is to redirect memory & cpu load to the file with the name of the tool.so am using the below script i am stucking how to redirect to the file... (2 Replies)
Discussion started by: ajaincv
2 Replies

3. Shell Programming and Scripting

I/O redirection

Hello everyone,I'm reading a book and there's code fragment: exec 3>&1 ls -l 2>&1 >&3 3>&- | grep bad 3>&- exec 3>&- It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Discussion started by: homeboy
18 Replies

4. UNIX for Dummies Questions & Answers

Help with Redirection

Hi Guys, I m new to UNIX and new to this forum. Was wondering if someone can help me understand redirection (standard input output pipeline etc) for starters, not too sure what this would mean who | sort > sortedfile | pr | lp im starting to understand common commands but when throwing... (2 Replies)
Discussion started by: jmack123
2 Replies

5. UNIX for Dummies Questions & Answers

stdin redirection

Hello, my C application under unix runs in redirecting stdin to a file. Example:$appli1 <file1. This application waits often on a scanf(). But I would temporarely reassign stdin at the keyboard for waiting a user's answer. So I thought to add system("appli2"); in the code of appli1. In its... (4 Replies)
Discussion started by: cypleen
4 Replies

6. Shell Programming and Scripting

Redirection using csh

I have a csh script which I am using to run a program set data = $argv set inmod = $argv set nxz = $argv # Remove the file extension .pmod set data = ` echo $data | awk 'BEGIN { FS=".dat" } { print $1 }' ` set inmod = ` echo $inmod | awk 'BEGIN { FS=".vmod" } { print... (8 Replies)
Discussion started by: kristinu
8 Replies

7. Web Development

Auto redirection in Perl

Hello, I am currenlty using a link to go back to previous page in Perl-CGI. Now I want to auto redirect the page after 5 seconds. Can anybody help!!!! (1 Reply)
Discussion started by: gentleDean
1 Replies

8. Shell Programming and Scripting

Perl Redirection

Hi, I have a Perl script that finds some files based on some criteria and then it processes the file contents using some logic. Extract: print "Started ... "; my $command = "<unix command>"; @arr=`$command`; $size=@arr; print "Size: ".$size If I turn on the Perl debugging option then I... (3 Replies)
Discussion started by: King Nothing
3 Replies

9. Shell Programming and Scripting

redirection

Hi, The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale. Now the proble is: How can I redirect stderr to a file? PS: so I want to redirect ALL the errors to a file. I tryed... (9 Replies)
Discussion started by: DNAx86
9 Replies

10. Programming

Help with redirection

Here is my problem. I don't know make this redirection thing work. The output file (called output.c) looks like this #include<stdio.h> int main() { int k; int m; print f("%d\n", k); printf("%d\n", m); return 0; } the input file(called input.c) is this #include<stdio.h> int... (2 Replies)
Discussion started by: Shallon1
2 Replies
Login or Register to Ask a Question