Perl Module Lwp::simple Learning

Source: Internet
Author: User

  1. How does the
  2. Use this module in Perl?
    Use lwp::simple;

    2. How do I get a page content?
    My $content = Get (' http://www.yahoo.com.cn '); The

    Get function assigns all the page contents obtained from www.yahoo.com.cn to the $content variable, and
    returns a undef value if the fetch fails.

    3. How do I get the head?
    My (b, D, $e) = Head (' http://www.yahoo.com.cn ');

    If the get successful head function returns five variables, $a-e represents the content type, document length, most
    post-update time, expiration, and server name, respectively.

    4. How do I export the contents of a specified page?
    My $code = Getprint (' http://www.yahoo.com.cn ');

    Getprint will attempt to print the contents of the www.yahoo.com.cn and return a status number, such as a successful
    return of 200, and a file not found will return 404.

    5. How do I save the captured content to a file?
    My $code = GetStore (' http://www.yahoo.com.cn ', '/path/file.html '); The

    GetStore will attempt to save the obtained content to the file specified in the second parameter, returning a status number with the form of the
    status number as above.

    6. How do I synchronize remote and local files?
    My $code = Mirror (' http://www.yahoo.com.cn ', '/path/file.html '); The

    Mirror function compares the remote and local file consistency and returns a status number, such as the same file
    will return 304 if the local file synchronization succeeds returns 200.

    7. How do I test the correctness of the return status?
    Is_success ($code)
    Is_error ($code)

    Is_success and Is_error These two functions can pass a status number as a parameter, and the program will determine whether the returned
    is a successful state. For example, Is_success (403) will return false.

#!/usr/bin/perl-w
Use strict;
Use Lwp::simple QW (GET);

My $url = Shift | | "http://www.chinaunix.net";
My $content = Get ($url);

Print $content;

Exit 0;
The easiest way to get a Web page.



Perl Module Lwp::simple Learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.