In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use Perl to crawl web pages and submit forms, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Use Perl to crawl web pages and submit forms
Here is a brief introduction to the use of Perl to achieve grab web page source code, and the use of POST method to submit the form, and return the results. I can't tell you what's difficult, but let's talk about something simple.
The Perl modules mentioned here are:
UseLWP::Simple;useLWP::UserAgent; uses Perldoc to see the detailed usage.
1. Crawl web pages with Perl
If you just want to get a web page, it's easiest to use the functions in LWP::Simple. By calling the get ($url) function, you can get the contents of the relevant URL.
My$url=' http://freshair.npr.org/dayFA.cfm?todayDate=current' useLWP::Simple; my$content=get$url; die "Couldn'tget$url" unlessdefined$content
# $content is the content of the web page, here is some analysis of this content:
If ($content=~m/jazz/i) {print "They'retalkingaboutjazztodayonFreshAir!\ n";} else {print "FreshAirisapparentlyjazzlesstoday.\ n";}
It's very easy to understand. It is easy to get the content of a web page, but it is difficult to filter the content you need with rules.
2. Submit the form through POST
Some HTML tables use HTMLPOST to submit data to the server, here you can do this:
$response=$browser- > post ($url, [formkey1= > value1, formkey2= > value2,...],)
Example analysis: for example, submit a sequence in http://www.enzim.hu/hmmtop/html/submit.html) and return the result, which is realized by Perl. The code is as follows:
#! / usr/bin/Perl useLWP::UserAgent; my$browser=LWP::UserAgent- > new; $protein= "MSSSTPFDPYALSEHDEERPQNVQSKSRTAELQAEIDDTVGIMRDNINKVAERGERLTSI"; my$SUSUI_URL= "http://www.enzim.hu/hmmtop/server/hmmtop.cgi"; my$response=$browser- > post ($SUSUI_URL, ['if'= > $protein,]); if ($response- > is_success) {print$response- > content;} else {print" Badluckthistime\ n ";}
By analyzing the page of http://www.enzim.hu/hmmtop/html/submit.html, we can see that there is only one input to be submitted, that is, name= "if". $protein is the sequence to be submitted. $response- > content is the result returned.
Thank you for reading this article carefully. I hope the article "how to use Perl to crawl web pages and submit forms" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.