Perl楽しいから好き

Perlをはじめとしたプログラミング周りのあれこれについて。モダーンなPerlを楽しんでいます。

下層ページもチェックできるようにしました。---Yahoo::Searchモジュールをjp仕様にして、YahooJapan検索順位を1000位まで順位チェックする


赤い文字が変更箇所です。


#!/usr/bin/perl -w
#
#Yahoo::Search_jpを使って特定URLの1000位までの順位をチェックする

use strict;
use Yahoo::Search_jp;
use encoding qw(shiftjis);


my $target_url="http://ameblo.jp/rumifu-blog/";
my $target_words="米沢瑠美";
my $language='ja'; #default=>undef
my $appid="あなたのYahooアプリケーションID";

my @Results = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 0,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "100位まで調べました。\n";

my @Results2 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 100,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results2){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "200位まで調べました。\n";

my @Results3 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 200,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results3){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "300位まで調べました。\n";

my @Results4 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 300,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results4){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "400位まで調べました。\n";

my @Results5 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 400,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results5){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "500位まで調べました。\n";

my @Results6 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 500,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results6){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "600位まで調べました。\n";

my @Results7 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 600,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results7){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "700位まで調べました。\n";

my @Results8 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 700,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results8){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "800位まで調べました。\n";

my @Results9 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 800,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results9){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "900位まで調べました。\n";

my @Results10 = Yahoo::Search_jp->Results(Doc => $target_words,
AppId => $appid,
# The following args are optional.
# (Values shown are package defaults).
Mode => 'all', # all words
Start => 900,
Count => 100,
Type => 'any', # all types
AllowAdult => 1, # including porn
AllowSimilar => 0,
Language => $language,
);

for my $Result (@Results10){
if ( $Result->Url =~ /$target_url/ ){
printf "Result: #%d\n", $Result->I + 1,
printf "Url:%s\n", $Result->Url;
printf "%s\n", $Result->ClickUrl;
printf "Summary: %s\n", $Result->Summary;
printf "Title: %s\n", $Result->Title;
printf "In Cache: %s\n", $Result->CacheUrl;
print "\n";
}else{
1;
}
}

print "1000位まで調べました。\n";


で、検索結果がこれ↓

ちゃんとYahooのルール通り、
ドメイン以下2つのURLをキャッチできてる。

前回の課題が一つ解決したナリ。