如何使用 Perl 的 Google::Search 来查找特定的 URL?

发布于 2024-09-24 04:27:12 字数 524 浏览 1 评论 0原文

基于 AJAX 搜索 API 的 Google::Search 模块似乎工作得不太好,或者只是我的问题?

例如,我使用 Firefox 在 google 中搜索: http://bloggingheads.tv/forum /member.php?u=12129

它带来了结果。

但是当我以这种方式使用该模块时:

$google_search = Google::Search->Web ( q => "http://bloggingheads.tv/forum/member.php?u=12129" );
@result =  $google_search->all;

我在数组中什么也没有得到。

有什么想法吗?

似乎这个 API 并没有带来与手动搜索相同的结果,我是否遗漏了一些东西?

The Google::Search module, which is based on the AJAX Search API, doesn't seems to work very well, or it is just me?

For example, I use firefox to search google for: http://bloggingheads.tv/forum/member.php?u=12129

It brings results.

But when I use the module this way:

$google_search = Google::Search->Web ( q => "http://bloggingheads.tv/forum/member.php?u=12129" );
@result =  $google_search->all;

I get nothing in the array.

Any idea?

Seems like this API doesn't bring the same results like when searching manually, am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小清晰的声音 2024-10-01 04:27:12

我在西里尔文查询中也遇到了类似的问题。 CPAN 的 Google::SearchREST::Google 都不适合我 - 与手动测试相比,它们返回的结果较少或没有。

最终我使用 WWW::Mechanize 和 HTML::TreeBuilder 编写了一个抓取模块。

这是获取结果统计信息的示例:

my $tree = HTML::TreeBuilder->new_from_content($content);

if (my $div = $tree->look_down(_tag => 'div', id => 'resultStats')) {
    my $stats = $div->as_text();
}
else { warn "no stats" }

I had a similar problem with cyrillic queries. Both Google::Search and REST::Google from CPAN didn't work for me - they were giving back fewer or no results compared to manual test.

Eventually I wrote a scraping module using WWW::Mechanize and HTML::TreeBuilder.

Here's a sample to get result stats:

my $tree = HTML::TreeBuilder->new_from_content($content);

if (my $div = $tree->look_down(_tag => 'div', id => 'resultStats')) {
    my $stats = $div->as_text();
}
else { warn "no stats" }
聆听风音 2024-10-01 04:27:12

查看 Google::Search 的 POD ,看起来它希望您将搜索词传递到 Web,而不是 URL。我从 CPAN 下载了测试脚本,并运行了它,它似乎产生了预期的结果:

use strict;
use warnings;
use Google::Search;

my $search = Google::Search->Web(q => "rock");
my $result = $search->first;
while ($result) {
    print $result->number, " ", $result->uri, "\n";
    $result = $result->next;
}
print $search->error->reason, "\n" if $search->error;

__END__

0 http://www.rock.com/
1 http://en.wikipedia.org/wiki/Rock_music
2 http://en.wikipedia.org/wiki/Rock_(geology)
3 http://rockyourphone.com/
4 http://rockhall.com/
5 http://www.co.rock.mn.us/
6 http://www.co.rock.wi.us/
7 http://www.rockride.org/
etc...

我意识到这并没有具体回答你的问题,但也许它会引导你走向正确的方向。

Looking at the POD for Google::Search, it looks like it expects you to pass search terms to Web, instead of a URL. I downloaded a test script from CPAN, ran it, and it seems to produce expected results:

use strict;
use warnings;
use Google::Search;

my $search = Google::Search->Web(q => "rock");
my $result = $search->first;
while ($result) {
    print $result->number, " ", $result->uri, "\n";
    $result = $result->next;
}
print $search->error->reason, "\n" if $search->error;

__END__

0 http://www.rock.com/
1 http://en.wikipedia.org/wiki/Rock_music
2 http://en.wikipedia.org/wiki/Rock_(geology)
3 http://rockyourphone.com/
4 http://rockhall.com/
5 http://www.co.rock.mn.us/
6 http://www.co.rock.wi.us/
7 http://www.rockride.org/
etc...

I realize this does not specifically answer your question, but perhaps it steers you in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文