blog/content/post/2009/06/21/2009-06-21-00001178.md

62 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 銀座ルノアールの店舗情報を取得
author: kazu634
date: 2009-06-21
url: /2009/06/21/_1274/
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4659;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- Perl
---
<div class="section">
<p>
Google Mapsにマッピングしようとして、住所情報を取得するPerlスクリプトを作成してみましたスターバックスはちょっと難しいので後でやる
</p>
<p>
Web::Scraperは便利だ♪
</p>
<pre class="syntax-highlight">
<span class="synComment"># === Libraries ===</span>
<span class="synStatement">use strict</span>;
<span class="synStatement">use warnings</span>;
<span class="synStatement">use </span>URI;
<span class="synStatement">use </span>Web::Scraper;
<span class="synStatement">use </span>YAML;
<span class="synStatement">use </span>Encode;
<span class="synStatement">use utf8</span>;
<span class="synStatement">my</span> <span class="synIdentifier">@address</span>;
<span class="synComment"># === Main part ===</span>
<span class="synStatement">my</span> <span class="synIdentifier">$frame</span> = scraper {
process <span class="synConstant">'//td[@class=&#34;line_a&#34; and @bgcolor=&#34;#ffffff&#34;]//a'</span>,
<span class="synConstant">'shop[]'</span> =&#62; <span class="synConstant">'@href'</span>;
};
<span class="synStatement">my</span> <span class="synIdentifier">$res</span> =
<span class="synIdentifier">$frame</span>-&#62;scrape( URI-&#62;<span class="synStatement">new</span>(<span class="synConstant">&#34;http://www.ginza-renoir.co.jp/renoir/index.htm&#34;</span>) );
<span class="synComment"># print encode('utf8', YAML::Dump($result-&#62;{body}));</span>
<span class="synStatement">foreach</span> <span class="synStatement">my</span> <span class="synIdentifier">$x</span> ( @{ <span class="synIdentifier">$res</span>-&#62;{shop} } ) {
<span class="synStatement">my</span> <span class="synIdentifier">$main</span> = scraper {
process <span class="synConstant">'//td[@bgcolor=&#34;#ffffff&#34; and @align=&#34;left&#34;]'</span>,
<span class="synConstant">'shopinfo[]'</span> =&#62; <span class="synConstant">'TEXT'</span>;
};
<span class="synStatement">my</span> <span class="synIdentifier">$part</span> = scraper {
process
<span class="synConstant">'/html/body/center[2]/center/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody'</span>,
<span class="synConstant">'shop'</span> =&#62; <span class="synIdentifier">$main</span>;
result <span class="synConstant">'shop'</span>;
};
<span class="synStatement">my</span> <span class="synIdentifier">$result</span> = <span class="synIdentifier">$part</span>-&#62;scrape(
URI-&#62;<span class="synStatement">new</span>(<span class="synIdentifier">$x</span>) );
<span class="synStatement">foreach</span> <span class="synStatement">my</span> <span class="synIdentifier">$y</span> ( @{ <span class="synIdentifier">$result</span>-&#62;{shopinfo} } ) {
<span class="synStatement">push</span>(<span class="synIdentifier">@address</span>, encode(<span class="synConstant">'utf8'</span>, <span class="synIdentifier">$y</span>)) <span class="synStatement">if</span> (<span class="synIdentifier">$y</span> =~<span class="synStatement"> /</span><span class="synConstant">^東京都</span><span class="synStatement">/</span>);
<span class="synStatement">push</span>(<span class="synIdentifier">@address</span>, encode(<span class="synConstant">'utf8'</span>, <span class="synIdentifier">$y</span>)) <span class="synStatement">if</span> (<span class="synIdentifier">$y</span> =~<span class="synStatement"> /</span><span class="synConstant">^神奈川県</span><span class="synStatement">/</span>);
}
<span class="synStatement">foreach</span> (<span class="synIdentifier">@address</span>) {
<span class="synStatement">print</span>(<span class="synConstant">&#34;</span><span class="synIdentifier">$_</span><span class="synSpecial">\n</span><span class="synConstant">&#34;</span>);
}
<span class="synComment"># print encode( 'utf8', YAML::Dump($result) );</span>
}
</pre>
</div>