• LWP::UserAgent介绍2


     1 #这个LWP::UserAgent一般要配合其他模块使用
     2 #比如:
     3 #HTTP::Request
     4 #HTTP::Cookie
     5 #HTTP::Respose
     6 #HTTP::Status
     7 #LWP::UserAgent相当于创建一个模拟浏览器
     8  
     9 #用以下方式创一个浏览器
    10 my $useragent = LWP::UserAgent->new();
    11 #一般来说, 我们参数不添加, 到下面要用时再添加, 或让它使用默认值, 它的默认参数如下
    12  
    13 =pod
    14            KEY                     DEFAULT
    15            -----------             --------------------
    16            agent                   "libwww-perl/#.###"
    17            from                    undef
    18            conn_cache              undef
    19            cookie_jar              undef
    20            default_headers         HTTP::Headers->new
    21            local_address           undef
    22            ssl_opts                { verify_hostname => 1 }
    23            max_size                undef
    24            max_redirect            7
    25            parse_head              1
    26            protocols_allowed       undef
    27            protocols_forbidden     undef
    28            requests_redirectable   ['GET', 'HEAD']
    29            timeout                 180
    30 =cut
    31  
    32 如果你想添加参数, 用这种形式:
    33 my $useragent = LWP::UserAgent->new(agent => 'PERL');
    34 =pod
    35 一般来说, 我们不用配置他上面的参数
    36 当然, 如果你想测试一下, 可以用下面的代码打印一下默认值, 但不一定能正常打印
    37 =cut
    38  
    39 #!/usr/bin/perl -w
    40 use strict;
    41 use LWP::UserAgent;
    42  
    43 my $ua = LWP::UserAgent->new();
    44 print $ua->agent,"
    ";
    45 print $ua->from,"
    ";
    46 print $ua->conn_cache,"
    ";
    47 print $ua->cookie_jar,"
    ";
    48 print $ua->default_headers,"
    ";
    49 print $ua->local_address,"
    ";
    50 print $ua->ssl_opts,"
    ";
    51 print $ua->max_size,"
    ";
    52 print $ua->max_redirect,"
    ";
    53 print $ua->parse_head,"
    ";
    54 print $ua->protocols_allowed,"
    ";
    55 print $ua->protocols_forbidden,"
    ";
    56 print $ua->requests_redirectable,"
    ";
    57 print $ua->timeout,"
    ";
    58  
    59 #可以看到有一些值是要从其他模块去获得的, 像$ua->default_headers, 要从HTTP::Headers->new去构建
  • 相关阅读:
    opencv(8)直方图操作
    opencv(9)直方图均衡化,对比,匹配
    最近没有更新日记
    dsp 链接命令文件的写法
    sqlserver 的数据库备份 还原安全操作 备忘录
    主板的各种抱错声音
    hibernate 的自动生成工具
    如何学习,如何提出问题,如何解决问题,如何脑筋急转弯
    framework 的 错误提示?
    hack 入侵 142 主机的过程
  • 原文地址:https://www.cnblogs.com/perl6/p/6136218.html
Copyright © 2020-2023  润新知