CMO*_*MOS 0 java perl copy-paste web-scraping
特别是我想知道在java(首选)或perl是否可以输入一个网址并让它从该页面复制文本?具体来说,我希望能够在谷歌上搜索一些东西,只需复制粘贴出现的前5个链接.不做SEO或任何它只是为我正在努力的程序.
在Java上不确定(我确定它是可能的)但是对于Perl你可以尝试CPAN模块LWP/UserAgent可以轻松抓取页面
http://search.cpan.org/~gaas/libwww-perl-6.03/lib/LWP/UserAgent.pm
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://search.cpan.org/');
if ($response->is_success) {
print $response->decoded_content; # or whatever
}
Run Code Online (Sandbox Code Playgroud)
看到你上面的评论,所以我想补充一下.在Perl中剥离空格很容易:
$string =~ s/\s//g;
Run Code Online (Sandbox Code Playgroud)
或适用于上述代码
$response->decoded_content =~ s/\s//g;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5375 次 |
最近记录: |