In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how perl automatically obtains the information on the web page. I hope you will get something after reading this article. Let's discuss it together.
Perl gets the information on the web page
Perl automatically surfs the Internet and then gets the information on the web page:
#! / usr/bin/perl-w # Perl pragma to restrict unsafe constructsuse strict;# use LWP::UserAgent modeluse LWP::UserAgent; # main functionsub main {# get params # @ _ # Within a subroutine the array @ _ contains the parameters passed to that subroutine. # Inside a subroutine, @ _ is the default array for the array operators push, pop, shift, and unshift. My $url = 'http://www.taobao.com'; die "no url param!\ n" unless $url; # create LWP::UserAgent object my $ua = LWP::UserAgent- > new; # set connect timeout $ua- > timeout (20); # set User-Agent header $ua- > agent ("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727)") # send url use get mothed, and store response at var $resp my $resp = $ua- > get ($url); # check response if ($resp- > is_success) {# get response content (html source code) my $content = $resp- > decoded_content; # use Regex get page title from $content if ($content = ~ m {(. *)} si) {# (. +?) (. +?) Match title string, use () to store this str at a special variable $1 (this is a perl variable), # The bracketing construct (...) Creates capture groups (also referred to as capture buffers). To refer to the current contents of a group later on, within the same pattern, use $1 for the first,$2 for the second, and so on. My $head = $1; print "find page title: $head\ n";} else {print "no page title for url: $url\ n";}} else {# display status information and exit die $resp- > status_line;}} # pass params to main function,# @ ARGV# The array @ ARGV contains the command-line arguments intended for the script. Main (@ ARGV); after reading this article, I believe you have a certain understanding of "how perl automatically gets the information on the web page". If you want to know more about it, please follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.