Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Talk to Bob

by chunlou (Curate)
on Aug 03, 2003 at 07:16 UTC ( [id://280408]=CUFP: print w/replies, xml ) Need Help??

Talk to Bob via the Internet by running the interactive script. Press Ctrl-C to quit.
use strict; use warnings; use HTTP::Request; use LWP::UserAgent; use HTML::Form; print "Initializing...\n\n"; my $agent = "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/2003 +0624"; my $url = "http://www.pandorabots.com/pandora/talk?botid=e48a36fe6e34d +0a6"; my $form = initform($agent, $url); my $reply = getreply("hi there", $form); print "Bob says> $reply\n\n"; print " You say> "; while (<STDIN>) { $reply = getreply($_, $form); print "Bob says> $reply\n\n"; print " You say> "; } sub initform { my ($agent, $url) = @_; my $ua = new LWP::UserAgent(agent=>$agent); my $request = new HTTP::Request('GET', $url); my $response = $ua->request($request); my $html = $response->content; my $form = HTML::Form->parse($html, $url); return $form; } sub getreply { my ($msg, $form) = @_; $form->value(message => $msg); my $response = LWP::UserAgent->new->request($form->click); my $reply = $response->content; $reply =~ /<b>mytest:<\/b>\s*(.*?)<br>/s; return $1; }

Replies are listed 'Best First'.
Re: Talk to Bob
by djbiv (Scribe) on Aug 04, 2003 at 13:21 UTC
    I'd really like to be able to talk to Bob! unfortunately it is not working for me, I can access the the url that is stored in $url via a web browser but when I run the code I get the following error causing me problems: Can't call method "value" on an undefined value at C:\Documents and Settings\me\My Documents\work\perl\bob.pl line 35. So I figured I'd check out what I retrieved from $respons->content; This is what's retrieved
    Initializing... <DIV class=Section1> <P class=MsoNormal style="mso-list: none; mso-list-ins: '' 19991102T2025" +>&nbsp; </P> <TABLE border=1 cellPadding=0 style="BORDER-BOTTOM: 4.5pt outset; BORDER-LEFT: 4.5pt + outset; BORDER-RIGHT: 4.5pt outset; BORDER-TOP: 4.5pt outset; WIDTH: 100%; m +so-cellspacing: 1.5pt" width="100%"> <TBODY> <TR> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="22%" valign="top"> <P class=MsoNormal><B>Problem Report</B></P> </TD> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="78%" valign="top"> <P class=MsoNormal>The Web proxy was not able to authe +nticate you through the authentication server because:&#32&#32<b>General a +uthentication failure due to bad user ID or authentication token.</b> You will not be able to browse the Web through this pr +oxy until your credentials can be retrieved and verified.</P> </TD> </TR> <tr> <td style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="22%" valign="top"> <p class=MsoNormal><b>Message ID</b></p> </td> <td style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="22%" valign="top"> <p class=MsoNormal>WWW_AUTH_FAIL_OTHER <p></p> </td> </tr> <TR> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="22%" valign="top"> <P class=MsoNormal><B>Problem Description</B></P> </TD> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="78%" valign="top"> <P class=MsoNormal>The user verification was not succe +ssful.</P> </TD> </TR> <TR> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; ADDING-TOP: 0.75pt" width="22%" valign="top"> <P class=MsoNormal><B>Problem Cause</B></P> </TD> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="78%" valign="top"> <P class=MsoNormal>This might be due to transient netw +ork problems or due to the user's not being authorized to use this Web proxy.</P> </TD> </TR> <TR> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="22%" valign="top"> <P class=MsoNormal><B>Possible Solution</B></P> </TD> <TD style="PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; P +ADDING-RIGHT: 0.75pt; PADDING-TOP: 0.75pt" width="78%" valign="top"> <P class=MsoNormal>Contact your network su +pport team if this problem persists, and provide th +e team your account information.</P> </TD> </TR> </TBODY> </TABLE> Can't call method "value" on an undefined value at C:\Documents and Se +ttings\me\My Documents\work\perl\bob.pl line 35. <p>&nbsp;</p>
    Any ideas, I'd really like to talk to Bob!

      It looks like you're going through a proxy server. Maye be that's why LWP::UserAgent didn't work. You shouldn't try to make it work however if that means you need to put some proxy information in the script. It's not considered a good security practice.

      On IE browser, you may go to Tools > Internet Options > Connections > LAN Settings to see if in fact you're using a proxy. On Netscape or Mozilla, Edit > Preferences > Advanced > Proxies.

      If you use AOL like that, all the web contents are cached on the server side and you can do nothing about it.

      Should you post for further help, remember DON'T post your proxy settings on the web. It could be risky.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://280408]
Approved by jeffa
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-26 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found