- How does the
-
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