簡體   English   中英

從“ Yahoo!”運行perl hack Google中的目錄Mindshare”

[英]Running perl hack from “Yahoo! Directory Mindshare in Google”

有人運行過http://oreilly.com/pub/h/974#code提供的 perl腳本嗎?

這是一個著名的網址,用於從Yahoo!獲取URL。 目錄,很多人已經成功使用它。

我正在嘗試獲取URL。 我創建了自己的Google API密鑰,並將其替換為代碼。 除此之外,我沒有做任何改變。

腳本既不會產生任何錯誤,也不會產生任何URL。

#!/usr/bin/perl -w

use strict;
use LWP::Simple;
use HTML::LinkExtor;
use SOAP::Lite;

my $google_key  = "your API key goes here";
my $google_wdsl = "GoogleSearch.wsdl";
my $yahoo_dir   = shift || "/Computers_and_Internet/Data_Formats/XML_  _".
              "eXtensible_Markup_Language_/RSS/News_Aggregators/";

# download the Yahoo! directory.
my $data = get("http://dir.yahoo.com" . $yahoo_dir) or die $!;

# create our Google object.
my $google_search = SOAP::Lite->service("file:$google_wdsl");
my %urls; # where we keep our counts and titles.

# extract all the links and parse 'em.
HTML::LinkExtor->new(\&mindshare)->parse($data);

sub mindshare { # for each link we find...

  my ($tag, %attr) = @_;

  print "$tag\n";   

  # continue on only if the tag was a link,

  # and the URL matches Yahoo!'s redirectory.

  return if $tag ne 'a';   

  return unless $attr{href} =~ /srd.yahoo/;

  return unless $attr{href} =~ /\*http/;



  # now get our real URL.

  $attr{href} =~ /\*(http.*)/; my $url = $1;

  print "hi";

  # and process each URL through Google.

  my $results = $google_search->doGoogleSearch(

                      $google_key,"link:$url", 0, 1,

                      "true", "", "false", "", "", ""

                ); # wheee, that was easy, guvner.

  $urls{$url} = $results->{estimatedTotalResultsCount};

  print "1\n";

} 

# now sort and display.

my @sorted_urls = sort { $urls{$b} <=> $urls{$a} } keys %urls;

foreach my $url (@sorted_urls) { print "$urls{$url}: $url\n"; }

程序進入循環,並在第一次迭代時出現“我的@sorted_urls = sort {$ urls {$ b} <=> $ urls {$ a}}鍵%urls;”。

我對perl沒有任何了解,但這項任務本來應該是微不足道的。

當然,我缺少一些非常明顯的東西,因為該腳本已被許多人成功使用。

提前致謝。

您是否在向腳本提供目錄? 因為如果不是,那么腳本中的這一行

"/Computers_and_Internet/Data_Formats/XML_  _".
              "eXtensible_Markup_Language_/RSS/News_Aggregators/"

不是格式化文物,則您要嘗試抓取不存在的頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM