以下のコードを実行すると
404 Not Found at script.pl line 31
と出てしまいます。
少し前の本でURLが変わったのか分かりませんが
どう対応していいのか分かりません・・・
use strict; use warnings; use SOAP::Lite; use URI; use LWP::Simple; use XML::Simple; use encoding 'UTF-8'; # 使用しているプラットフォームにあわせてください。 binmode(STDERR, ':raw :encoding(UTF-8)'); # 同上 use Encode; # Google APIを使用するために必要となる情報 my $google_key = "yourgoogleapikey"; my $google_wdsl = "GoogleSearch.wsdl"; my $gsrch = SOAP::Lite->service("file:$google_wdsl"); my $query = join(" ", @ARGV) . ' site:co.jp'; my $numOfSample = 50; # Google から取得する結果の数を指定する。 my $start = 0; my %siteName; my %siteURL; while ($start < $numOfSample) { my $num = $numOfSample - $start; $num = 10 if $num > 10; # 検索を実行する。 my $result = $gsrch->doGoogleSearch($google_key, $query, $start, $num, "false", "", "false", "lang_jp", "", ""); # 結果を格納する。 foreach my $hit (@{$result->{'resultElements'}}){ my @args = ( cli => 10, dat => 'snba', ver => '7.0', url => $hit->{URL}, ); my $base = 'http://data.alexa.com/data'; my $uri = URI->new( $base ); $uri->query_form( @args ); my $content = decode('utf8', get($uri->as_string)); #print $content; exit; my $xml = XMLin( $content ); if (defined($xml->{SD}{POPULARITY}{TEXT})) { # トラフィックランクのあるもののみを登録する。 my $popularity = int($xml->{SD}{POPULARITY}{TEXT}); $siteName{$popularity} = $xml->{DMOZ}{SITE}{TITLE} # DMOZがあるもののみ登録する。 if defined($xml->{DMOZ}{SITE}{TITLE}); $siteURL{$popularity} = $xml->{DMOZ}{SITE}{BASE} if defined($xml->{DMOZ}{SITE}{BASE}); } } $start += 10; } # 結果をランクの高いもの順に表示する。 foreach my $p (sort { $a <=> $b } keys %siteName) { print "$p\t$siteName{$p}\t$siteURL{$p}\n"; } コード
以下はGoogleSearch.wsdlの中身です
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="urn:GoogleSearch" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="urn:GoogleSearch" name="GoogleSearch" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <s:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:GoogleSearch"> <s:complexType name="GoogleSearchResult"> <s:all> <s:element name="documentFiltering" type="s:boolean" /> <s:element name="searchComments" type="s:string" /> <s:element name="estimatedTotalResultsCount" type="s:int" /> <s:element name="estimateIsExact" type="s:boolean" /> <s:element name="resultElements" type="s0:ResultElementArray" /> <s:element name="searchQuery" type="s:string" /> <s:element name="startIndex" type="s:int" /> <s:element name="endIndex" type="s:int" /> <s:element name="searchTips" type="s:string" /> <s:element name="directoryCategories" type="s0:DirectoryCategoryArray" /> <s:element name="searchTime" type="s:double" /> </s:all> </s:complexType> <s:complexType name="ResultElement"> <s:all> <s:element name="summary" type="s:string" /> <s:element name="URL" type="s:string" /> <s:element name="snippet" type="s:string" /> <s:element name="title" type="s:string" /> <s:element name="cachedSize" type="s:string" /> <s:element name="relatedInformationPresent" type="s:boolean" /> <s:element name="hostName" type="s:string" /> <s:element name="directoryCategory" type="s0:DirectoryCategory" /> <s:element name="directoryTitle" type="s:string" /> </s:all> </s:complexType> <s:complexType name="ResultElementArray"> <s:complexContent mixed="false"> <s:restriction base="soapenc:Array"> <s:attribute d7p1:arrayType="s0:ResultElement[]" ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/" /> </s:restriction> </s:complexContent> </s:complexType> <s:complexType name="DirectoryCategoryArray"> <s:complexContent mixed="false"> <s:restriction base="soapenc:Array"> <s:attribute d7p1:arrayType="s0:DirectoryCategory[]" ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/" /> </s:restriction> </s:complexContent> </s:complexType> <s:complexType name="DirectoryCategory"> <s:all> <s:element name="fullViewableName" type="s:string" /> <s:element name="specialEncoding" type="s:string" /> </s:all> </s:complexType> </s:schema> </types> <message name="doGetCachedPage"> <part name="key" type="s:string" /> <part name="url" type="s:string" /> </message> <message name="doGetCachedPageResponse"> <part name="return" type="s:base64Binary" /> </message> <message name="doSpellingSuggestion"> <part name="key" type="s:string" /> <part name="phrase" type="s:string" /> </message> <message name="doSpellingSuggestionResponse"> <part name="return" type="s:string" /> </message> <message name="doGoogleSearch"> <part name="key" type="s:string" /> <part name="q" type="s:string" /> <part name="start" type="s:int" /> <part name="maxResults" type="s:int" /> <part name="filter" type="s:boolean" /> <part name="restrict" type="s:string" /> <part name="safeSearch" type="s:boolean" /> <part name="lr" type="s:string" /> <part name="ie" type="s:string" /> <part name="oe" type="s:string" /> </message> <message name="doGoogleSearchResponse"> <part name="return" type="s0:GoogleSearchResult" /> </message> <portType name="GoogleSearchPort"> <operation name="doGetCachedPage"> <input message="s0:doGetCachedPage" /> <output message="s0:doGetCachedPageResponse" /> </operation> <operation name="doSpellingSuggestion"> <input message="s0:doSpellingSuggestion" /> <output message="s0:doSpellingSuggestionResponse" /> </operation> <operation name="doGoogleSearch"> <input message="s0:doGoogleSearch" /> <output message="s0:doGoogleSearchResponse" /> </operation> </portType> <binding name="GoogleSearchBinding" type="s0:GoogleSearchPort"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" /> <operation name="doGetCachedPage"> <soap:operation soapAction="urn:GoogleSearchAction" /> <input> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </input> <output> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </output> </operation> <operation name="doSpellingSuggestion"> <soap:operation soapAction="urn:GoogleSearchAction" /> <input> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </input> <output> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </output> </operation> <operation name="doGoogleSearch"> <soap:operation soapAction="urn:GoogleSearchAction" /> <input> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </input> <output> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </output> </operation> </binding> <service name="GoogleSearchService"> <port name="GoogleSearchPort" binding="s0:GoogleSearchBinding"> <soap:address location="http://api.google.com/search/beta2" /> </port> </service> </definitions> コード
曖昧な質問ですが動くようにしたいです
アドバイスお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。