LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2013, 12:51 AM   #1
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
Perl URL redirect question


I have a URL(A) that redirects me to another URL(B). This URL(B) will redirect me to the final URL(C) and has an access code inside of the address bar. So a total of 3 redirects.

I can get the second URL(B), the redirect URL(B), but in order to obtain the 3rd redirect URL(C), I need to use the system call and open the URL(B) in the browser which redirects me to the third URL(C) which has the access code i need.

I need to get the access code with inside the address bar URL(C) without opening a browser tab. How can I accomplish this?

Last edited by amboxer21; 12-03-2013 at 12:58 AM.
 
Old 12-03-2013, 04:08 AM   #2
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Original Poster
Rep: Reputation: Disabled
This does it

Code:
my $ua = LWP::UserAgent->new;
my $response = $ua->get($uri);
print $response->request->uri . "\n";
But i recieve this error ->
Code:
https://www.facebook.com/unsupportedbrowser
I would assume because I am running it from a terminal.
 
Old 12-03-2013, 06:47 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Maybe you should 'emulate' some actual 'User-Agent' header, eg:

Mozilla/5.0 (X11; Linux i686 on x86_64; rv:25.0) Gecko/20100101 Firefox/25.0
 
1 members found this post helpful.
Old 12-03-2013, 07:00 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
This might be a question better posed at http://www.perlmonks.org.

Also, consider your overall approach. Facebook has a programmatic API that is intended for "program-to-program" activities, vs. those which rely upon a heavily JavaScript-driven browser. And, Perl has CPAN modules to interface with it (see http://search.cpan.org.

Articles like this one http://developeronline.blogspot.com/...ok-part-i.html are also plentiful and useful.

Yes indeed, FB does query your browser-type and will not go far if it doesn't recognize what your LWP instance claims to be. However, also note that FB "will not go far," in general, without resorting to JavaScript ... which is much more difficult to programmatically emulate. They're a pretty busy bunch of coders, constantly fiddling with their system's guts even when the external UI doesn't change visibly. Build your code with flexibility in mind, and put it under source-code control (such as "git") so that you can change it easily when they do.

Last edited by sundialsvcs; 12-03-2013 at 07:04 AM.
 
Old 12-03-2013, 12:34 PM   #5
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Maybe you should 'emulate' some actual 'User-Agent' header, eg:

Mozilla/5.0 (X11; Linux i686 on x86_64; rv:25.0) Gecko/20100101 Firefox/25.0
I think thats exactly what I need to do. Maybe the Mechanize constructor will do. Thanks!
 
Old 12-03-2013, 12:42 PM   #6
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
This might be a question better posed at http://www.perlmonks.org.
OK. I just figure there are so many intelligent and talente members here, yo never know what someone might be knowlegable about! I guess perlmonks wold be better suited though huh?

Quote:
Originally Posted by sundialsvcs View Post
Also, consider your overall approach. Facebook has a programmatic API that is intended for "program-to-program" activities, vs. those which rely upon a heavily JavaScript-driven browser. And, Perl has CPAN modules to interface with it (see http://search.cpan.org.
I am using the Facebook Graph module made for Perl. That only goes so far. I have a program up and running. I already wrote a GUI, have the login, OAuth, access token manipulation sub routines suited for the programs needs, etc. I am trying to fully automate my program. This browser redirect is the last step but i think NevemTeve, has the right idea!

Quote:
Originally Posted by sundialsvcs View Post
Articles like this one http://developeronline.blogspot.com/...ok-part-i.html are also plentiful and useful.
Thanks, I'l have a look.

Quote:
Originally Posted by sundialsvcs View Post
Yes indeed, FB does query your browser-type and will not go far if it doesn't recognize what your LWP instance claims to be. However, also note that FB "will not go far," in general, without resorting to JavaScript ... which is much more difficult to programmatically emulate. They're a pretty busy bunch of coders, constantly fiddling with their system's guts even when the external UI doesn't change visibly. Build your code with flexibility in mind, and put it under source-code control (such as "git") so that you can change it easily when they do.
I could use the selenium module if i wanted to use/interface with JS while using Perl.
 
  


Reply

Tags
perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script to parse url from xml URL Freaksta Linux - General 1 01-20-2011 07:46 PM
Cannot Redirect URL to another URL when the link is down with Squid marx_long Linux - Newbie 1 06-13-2010 08:59 PM
Hello. New old-timer with a URL-redirect question. phoyt LinuxQuestions.org Member Intro 3 12-17-2009 11:14 AM
Perl stderr&stdout redirect question Fredde87 Programming 5 03-26-2009 04:43 AM
url redirect Present Linux - Networking 4 01-26-2007 09:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration