- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl script to retrieve values from Web URL.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 07:07 AM
тАО11-09-2006 07:07 AM
After successful login, we need to retrieve value from filed тАЬTotalHitsтАЭ and store it in a flat file on our HP-UX server where we have latest Perl installed.
Thanks,
Gulam.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 07:33 AM
тАО11-09-2006 07:33 AM
Re: Perl script to retrieve values from Web URL.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1072865
This data is recovered by just such a script. You may be able to adapt the code and make it work for you.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 07:49 AM
тАО11-09-2006 07:49 AM
Re: Perl script to retrieve values from Web URL.
Thanks,
Gulam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 07:21 PM
тАО11-09-2006 07:21 PM
Re: Perl script to retrieve values from Web URL.
After that, maybe WWW::Mechanize is the tool for you
http://search.cpan.org/~petdance/WWW-Mechanize-1.20/
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 09:58 PM
тАО11-09-2006 09:58 PM
SolutionI would use LWP for this.
But if you have to undergo a more involved request-response cycle, probably with addidtional HTML scraping in-between
then indeed WWW::Mechanize is probably more appropiate.
I suppose that you can't directly access WWW sites but go over a proxy in your company?
In that case you would most likely also need to authorize with your WWW proxy.
Admittedly this is a bit trickier than using LWP::Simple.
You need to extra create an HTTP::Headers object which you need to populate with authorization headers for your WWW proxy as well as for all the realms of "secured" URL that you wish to GET or POST with your user agent.
Let me demonstrate this in the Perl debugger,
because we immediately can get a view of what HTTP headers are set.
$ perl -MLWP -MHTTP::Headers -de0
Loading DB routines from perl5db.pl version 1.19
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 0
DB<1> $h=HTTP::Headers->new
DB<2> $h->proxy_authorization_basic(qw(your_proxy_user your_proxy_passwd))
DB<3> x $h
0 HTTP::Headers=HASH(0x4055347c)
'proxy-authorization' => 'Basic eW91cl9wcm94eV91c2VyOnlvdXJfcHJveHlfcGFzc3dk'
The intimidatingly cryptic string in the proxy-autorization header field is nothing more than the Base64 encoding of "your_proxy_user:your_proxy_passwd".
We can easyli verify
DB<4> use MIME::Base64
DB<5> x decode_base64('eW91cl9wcm94eV91c2VyOnlvdXJfcHJveHlfcGFzc3dk')
0 'your_proxy_user:your_proxy_passwd'
Our user agent sends this automatically to the WWW proxy if it catches a 401 request
But you still need the authorize for the URL you want to GET.
So extend the HTTP header
DB<6> $h->authorization_basic(qw(url_to_get_user url_to_get_passwd))
DB<7> x $h
0 HTTP::Headers=HASH(0x4055347c)
'authorization' => 'Basic dXJsX3RvX2dldF91c2VyOnVybF90b19nZXRfcGFzc3dk'
'proxy-authorization' => 'Basic eW91cl9wcm94eV91c2VyOnlvdXJfcHJveHlfcGFzc3dk'
Now you need to signal your user agent that it should send the request to your WWW proxy instead of to the non-reachable target URL.
First we need to create a user agent
DB<8> $ua=LWP::UserAgent->new
DB<11> $ua->proxy([qw(http ftp)] => 'http://url.of.your.www-proxy:8888/')
DB<12> x $ua
0 LWP::UserAgent=HASH(0x4059ddd0)
'agent' => 'libwww-perl/5.68'
'from' => undef
'max_size' => undef
'no_proxy' => ARRAY(0x4059dd58)
empty array
'parse_head' => 1
'protocols_allowed' => undef
'protocols_forbidden' => undef
'proxy' => HASH(0x402b0648)
'ftp' => 'http://url.of.your.www-proxy:8888/'
'http' => 'http://url.of.your.www-proxy:8888/'
'requests_redirectable' => ARRAY(0x4055cd38)
0 'GET'
1 'HEAD'
'timeout' => 180
'use_eval' => 1
Alternatively you can set environmen vars like www_proxy and use the $ua->env_proxy method.
Let's try
DB<19> $ENV{http_proxy}='http://some.other.proxy-url:7777/'
DB<20> $ua->env_proxy
DB<21> x $ua->{proxy}
0 HASH(0x405ecf64)
'ftp' => 'http://url.of.your.www-proxy:8888/'
'http' => 'http://some.other.proxy-url:7777/'
DB<22>
See, it swallowed it.
Finally we need to put all parts together into a HTTP request.
DB<28> use HTTP::Request::Common
DB<30> $req=HTTP::Request->new(GET => 'http://url.you.want/', $h)
DB<31> x $req
0 HTTP::Request=HASH(0x40606bf0)
'_content' => ''
'_headers' => HTTP::Headers=HASH(0x40606be4)
'authorization' => 'Basic dXJsX3RvX2dldF91c2VyOnVybF90b19nZXRfcGFzc3dk'
'proxy-authorization' => 'Basic eW91cl9wcm94eV91c2VyOnlvdXJfcHJveHlfcGFzc3dk'
'_method' => 'GET'
'_uri' => URI::http=SCALAR(0x402a0620)
-> 'http://url.you.want/'
Finally you can send the request with your user agent.
Of course this won't work in my debugger session because I so far used only bogus data.
DB<32> $res=$ua->request($req)
DB<33> x $res->is_success
0 ''
DB<34> x $res
0 HTTP::Response=HASH(0x407ecfb4)
'_content' => ''
'_headers' => HTTP::Headers=HASH(0x407ecffc)
'client-date' => 'Fri, 10 Nov 2006 10:57:08 GMT'
'_msg' => 'Can\'t connect to some.other.proxy-url:7777 (Bad hostname \'some.other.proxy
-url\')'
'_rc' => 500
'_request' => HTTP::Request=HASH(0x40606bf0)
'_content' => ''
'_headers' => HTTP::Headers=HASH(0x40606be4)
'authorization' => 'Basic dXJsX3RvX2dldF91c2VyOnVybF90b19nZXRfcGFzc3dk'
'proxy-authorization' => 'Basic eW91cl9wcm94eV91c2VyOnlvdXJfcHJveHlfcGFzc3dk'
'user-agent' => 'libwww-perl/5.68'
'_method' => 'GET'
'_uri' => URI::http=SCALAR(0x402a0620)
-> 'http://url.you.want/'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 10:04 PM
тАО11-09-2006 10:04 PM
Re: Perl script to retrieve values from Web URL.
However it may be easier to just use the command line version and then process the output in your perl script.
curl -u name:password www.mysite.com
will do what you need, although
It can also do more complex "login and navigation" with session support if required.
The curl man page is at:
http://curl.haxx.se/docs/manpage.html
And you will also find links for downloading curl here.
Cheers
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2006 01:36 AM
тАО11-10-2006 01:36 AM
Re: Perl script to retrieve values from Web URL.
simply run the lwp-request script that comes with your Perl (but wget can be used equally easily).
e.g.
$ lwp-request -m get -C url_user:url_passwd http://requested.url.tld/some/url/path > if_its_not_html.dump
Btw, the source of lwp-request is a good example how you can sublass LWP::UserAgent and override get_basic_credentials to return for each visited realm the required authorization parameters.
Simply invoke "perldoc -m lwp-request", and search for get_basic_credentials in pager.