Chinaunix

标题: 自动聊天程序中html问题 [打印本页]

作者: mousimin    时间: 2013-02-26 10:51
标题: 自动聊天程序中html问题
大家好,想做一个跟simsimi聊天的perl程序,源码如下:
  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;
  4. use LWP;
  5. use HTTP::Cookies;
  6. use HTTP::Response;
  7. use LWP::ConnCache;
  8. use Encode;
  9. use FileHandle;

  10. my $lwp = LWP::UserAgent->new;
  11. my $conncache = new LWP::ConnCache;
  12. $lwp->conn_cache($conncache);
  13. my $file_log = "D:\\html.log";
  14. my $log = new FileHandle(">$file_log") || die "can not open $file_log\n";

  15. my $send_url = "http://www.simsimi.com/talk.htm";
  16. my %send_form = (
  17.          "userinput" => "how are you",
  18. );
  19. #my $send_cookie = qq~ sessionhash=$sessionhash; PHPSESSID=$passid~;
  20. #print "Send_Cookie $send_cookie\n";
  21. $lwp->default_header('Cookie'=>'aaa');
  22. my $send_response = $lwp->post($send_url,\%send_form);
  23. if ($send_response->is_success) {
  24.         my $html = $send_response->decoded_content;
  25.         my $start = '<table class="new-templete">';
  26.         my $end = '</table>';
  27.         my @find_all = ($html =~ /$start(.*?)$end/gs);
  28.         foreach(@find_all)
  29.         {
  30.                 print $log $_;
  31.         }
  32.         if (encode('gbk',$html) =~ /发送成功/) {
  33.                  print "Data send sucessful!";
  34.          }
  35.          else { print "Data send failed!"; }
  36. }
  37. else {
  38.         print "Data send error: ".$send_response->status_line;
  39. }
复制代码
记录到日志里边的内容是:


  1.                                 <tr>

  2.                                         <td class="bot">

  3.                                                 <div class="img-bot"></div>

  4.                                                 <div class="left-convo">Hi~!</div>

  5.                                         </td>

  6.                                 </tr>

  7.                                
复制代码
没有我想要的simsimi的回复,但是我在遨游的开发者工具中看到的html源码是有的:


请问我该怎样得到页面的全部源码呢?
作者: mousimin    时间: 2013-02-26 10:53
忘记说了,


  1.                                 <tr>

  2.                                         <td class="bot">

  3.                                                 <div class="img-bot"></div>

  4.                                                 <div class="left-convo">Hi~!</div>

  5.                                         </td>

  6.                                 </tr>

  7.                                
复制代码
这段中的Hi~!是你登陆到http://www.simsimi.com/talk.htm这个页面,simsimi就会默认发出的内容。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2