TitaniumMobile勉強記

Web系エンジニア向けのキャリアアドバイザーやってましたが現在はフリーランスで開発含めて色々やってます。技術ネタとしてはRuby/RailsとJavaScript関連(Node.js、Titanium)あたり

Yahoo のAPIを使った検索



ウェブ検索Webサービスのサンプルをほぼそのまま流用なんだけど、Yahoo で、派遣 CCNPというキーワードを使ってのソース。

#!/usr/local/bin/perl

#use strict;
use LWP::Simple;
use XML::Simple;


# Set your unique Yahoo! Application ID
my $appID = "xxxxxxxxxx";
my $query = "派遣 CCNP";

# Construct a Yahoo! JAPAN Web Search
my $base_url = "http://api.search.yahoo.co.jp/WebSearchService/V1/webSearch";
my $type = "all"; #alternates: any, phrase.
my $results = 100;
my $language = "ja";
my $results_sort = "rank"; #alternate: date.
my $req_url = "$base_url?appid=$appID&query=$query&results=$results";

$req_url .= "&language=$language&sort=$results_sort";

# Make the request
my $yahoo_response = get($req_url);

# Parse the XML
my $xmlsimple = XML::Simple->new();
my $yahoo_xml = $xmlsimple->XMLin($yahoo_response, ForceArray=>['Result']);

# Set some variables
my $out;
my $result_count = 0;

# Add the column header
my $totalresult = $yahoo_xml->{totalResultsAvailable};

# Loop through the items returned
foreach my $result (@{$yahoo_xml->{Result}}) {

$result_count++;
my $y_url = $result->{Url};
my $y_click_url = $result->{ClickUrl};
my $y_modificationdate = $result->{ModificationDate};
(my $sec,my $min,my $hour,my $mday,my $mon,my $year) = localtime($y_modificationdate);
$year += 1900; $mon++;
my $y_mimetype = $result->{MimeType};
my $y_cache = $result->{Cache}{Url};
my $y_cachesize = $result->{Cache}{Size};
if ($y_url eq "xxxxxxx") {
$out .= "○.$result_count.$y_url\n";
} else {
$out .= "$result_count.$y_url\n";
}
}

print $out;