{"id":2384,"date":"2011-05-04T23:49:00","date_gmt":"2011-05-04T14:49:00","guid":{"rendered":"https:\/\/hdmr.org\/d\/?e=1113"},"modified":"2011-05-04T23:49:00","modified_gmt":"2011-05-04T14:49:00","slug":"blogn-1113","status":"publish","type":"post","link":"https:\/\/hdmr.org\/d\/?e=1113","title":{"rendered":"\u6642\u523b\u8868\u30c7\u30fc\u30bf\u3092\u3046\u307e\u304f\u629c\u304d\u51fa\u3057\u3066\u304f\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u304a\u3068\u3068\u3044\u304b\u3089\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3060\u3068\u304b\u8a00\u3063\u3066\u308b\u3051\u3069\u3001Web\u30b5\u30a4\u30c8\u306eHTML\u3092\u89e3\u6790\u3057\u3066\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u3092\u53d6\u3063\u3066\u304f\u308b\u3053\u3068\u306e\u3053\u3068\u3067\u3042\u308b\u3002<\/p>\n<p>\u884c\u5100\u304c\u60aa\u3044\u65b9\u6cd5\u3060\u304c\u3001HTML\u3092\u89e3\u6790\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u5f97\u3089\u308c\u308b\u30c7\u30fc\u30bf\u306f\u591a\u3044\u3002<\/p>\n<hr \/>\n<p> \u50d5\u304c\u5b9f\u969b\u306b\u8fd1\u9244\u306eNextTrain\u306e\u30c7\u30fc\u30bf\u3092\u4f5c\u308b\u305f\u3081\u306b\u4f5c\u3063\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u307e\u3041\u306a\u306b\u304b\u3068\u3072\u3069\u3044\u306e\u3067\u3001  <\/p>\n<p>\u3053\u308c\u3092\u4f8b\u793a\u3059\u308b\u306e\u3082\u3072\u3069\u3044\u6c17\u304c\u3057\u305f\u306e\u3067\u3001\u6bd4\u8f03\u7684\u308f\u304b\u308a\u3084\u3059\u3044\u5927\u962a\u306e\u5e02\u30d0\u30b9\u306e\u6642\u523b\u8868\u3092\u4f8b\u306b\u53d6\u3063\u3066\u8a71\u3092\u3057\u3088\u3046\u3068\u601d\u3046\u3002<\/p>\n<p>\u304a\u307e\u3051\u3068\u3057\u3066\u5e02\u30d0\u30b962\u7cfb\u7d71\u306e\u6642\u523b\u8868\u3082\u4f5c\u3063\u3066\u304a\u3053\u3046\u3068\u601d\u3063\u305f\u3068\u304d\u306b\u3084\u3063\u305f\u3084\u308a\u304b\u305f\u3092\u793a\u3059\u3002<\/p>\n<p><a href=\"http:\/\/kensaku.kotsu.city.osaka.jp\/bus\/dia\/jikoku\/jikoku034484.html\">\u5927\u962a\u99c5\u524d \u30d0\u30b9\u6642\u523b\u8868 (62\u7cfb\u7d71\u30fb103\u7cfb\u7d71)<\/a><\/p>\n<p>\u3053\u3053\u304b\u308962\u7cfb\u7d71\u306e\u767a\u6642\u523b\u3092\u629c\u304d\u51fa\u3057\u305f\u3044\u3002<\/p>\n<p>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u308b\u3002\u3059\u308b\u3068class\u306btimetable\u304c\u6307\u5b9a\u3055\u308c\u305ftable\u8981\u7d20\u304c\u3042\u308b\u3002a\u8981\u7d20\u306b\u96a3\u63a5\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u305d\u306etable\u8981\u7d20\u306e\u4e0b\u306btr\u8981\u7d20\u304c\u3042\u3063\u30661\u6642\u9593\u3054\u3068\u306b\u51fa\u767a\u3059\u308b\u30d0\u30b9\u304c\u307e\u3068\u3081\u3089\u308c\u3066\u3044\u308b\u3002<\/p>\n<p>\u305d\u306e\u4e0b\u306b\u306fth\u8981\u7d20\u3068td\u8981\u7d20\u304c3\u3064\u306a\u3089\u3093\u3067\u3044\u3066\u3001th\u306f\u767a\u6642\u3001td\u305d\u308c\u305e\u308c\u306f\u5e73\u65e5\u30fb\u571f\u66dc\u30fb\u4f11\u65e5\u306e\u767a\u8eca\u3059\u308b\u30d0\u30b9\u3092\u793a\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u305d\u306etd\u8981\u7d20\u306e\u4e2d\u306b\u306f\u30d0\u30b9\u3054\u3068\u306bdiv\u8981\u7d20\u304c\u4e26\u3093\u3067\u3044\u3066\u3001\u6ce8\u91c8\u3092\u4ed8\u3051\u308bdiv\u8981\u7d20\u3068\u3001\u5206\u3092\u793a\u3059div\u8981\u7d20\u304c\u3042\u308b\u3002<\/p>\n<hr \/>\n<p> \u3055\u3066\u3001\u305d\u308c\u3092Perl\u306eWeb::Scraper\u3092\u4f7f\u3063\u3066\u629c\u304d\u51fa\u3057\u3066NextTrain\u306eTBL\u30c7\u30fc\u30bf\u306b\u52a0\u5de5\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u3053\u308c\u3060\u3002  <\/p>\n<pre>use strict;\nuse warnings;\nuse Encode;\nuse Web::Scraper;\nuse URI;\nuse utf8;\nmy $getdetailurl=scraper{\n  process \"\/\/table[\\@class='timetable'][1]\/colgroup\/tr[position()&gt;1]\",\"lines[]\"=&gt;scraper{\n    process \"\/\/th\",\"hour\"=&gt;'TEXT';\n    process \"\/\/td\",'section[]'=&gt;scraper{\n      process \"\/\/div[\\@class='item'][div[2]\/text()!='\u3000']\",'bus[]'=&gt;scraper{\n        process \"\/div\/div[1]\",'attr'=&gt;'TEXT';\n        process \"\/div\/div[2]\",'min'=&gt;'TEXT';\n      }\n    };\n  };\n};\nmy $res=$getdetailurl-&gt;scrape(URI-&gt;new(\"http:\/\/kensaku.kotsu.city.osaka.jp\/bus\/dia\/jikoku\/jikoku034484.html\"));\nopen my $ofh,'&gt;:encoding(shiftjis)','out.tbl';\nsub attr{\n  #if($_[0]=~m\/\u2605\/){ return ('NS'); }\n  #else            { return (); }\n}\nmy %attr=();\nsub todata{\n  my @res;\n  for(@{$_[0]}){\n    my @attr=attr($_-&gt;{'attr'});\n    $attr{$_}++ for @attr;\n    push @res,[$_-&gt;{'min'}+0,[@attr]];\n  }\n  return @res;\n}\nmy @data=([],[],[]);\nfor my $l(@{$res-&gt;{'lines'}}){\n  push @{$data[$_]} ,[$l-&gt;{'hour'}+0 , [todata($l-&gt;{'section'}-&gt;[$_]-&gt;{'bus'})] ] for 0..2;\n}\nmy $chr=ord('A');\nfor(keys(%attr)){\n  print $ofh chr($chr),':',$_.\"\\n\";\n  $attr{$_}=chr($chr);\n}\nprint $ofh \"\\n\";\nfor(0..2){\n  print $ofh ($_==0 ? \"[MON][TUE][WED][THU][FRI]\\n#(\u5e73\u65e5)\\n\" : $_==1 ? \"[SAT]\\n#(\u571f\u66dc)\\n\" : \"[SUN][HOL]\\n#(\u4f11\u65e5)\\n\");\n  for(@{$data[$_]}){\n    print $ofh $_-&gt;[0].': ';\n    for(@{$_-&gt;[1]}){\n      print $ofh $attr{$_} for @{$_-&gt;[1]};\n      print $ofh $_-&gt;[0],' ';\n    }\n    print $ofh \"\\n\";\n  }\n  print $ofh \"\\n\"\n}<\/pre>\n<p>\u3053\u306e\u4e2d\u3067Web::Scraper\u3067\u51e6\u7406\u3092\u3057\u3066\u3044\u308b\u306e\u306f\u6700\u521d\u306e\u65b9\u3067\u3042\u308b\u3002<\/p>\n<p>scraper{ \u2026 } \u3068\u3044\u3046\u98a8\u306b\u66f8\u3051\u3070\u51e6\u7406\u306e\u305f\u3081\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5f97\u3089\u308c\u308b\u3002<\/p>\n<p>{ \u2026 } \u306b\u306f\u51e6\u7406\u306e\u5185\u5bb9\u3092\u66f8\u304d\u8fbc\u3080\u304c\u3001process\u3067\u306fXPath\u307e\u305f\u306fCSS\u30bb\u30ec\u30af\u30bf\u3067\u6307\u5b9a\u3057\u305f\u8981\u7d20\u306b\u3064\u3044\u3066\u3068\u3084\u304b\u304f\u3059\u308b\u3053\u3068\u304c\u304b\u3051\u308b\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3042\u3048\u3066XPath\u5f0f\u3067\u66f8\u3044\u3066\u307f\u305f\u3002<\/p>\n<p>\/\/table[@class=&#8217;timetable&#8217;][1]\/colgroup\/tr[position()&gt;1] \u3068\u3044\u3046XPath\u5f0f\u3067\u3001class\u304ctimetable\u306etable\u8981\u7d20\u306e\u6700\u521d\u306e\u3082\u306e\u306e\u76f4\u4e0b\u306ecolgroup\u76f4\u4e0b\u306etr\u8981\u7d20\u306e\u3046\u30612\u756a\u76ee\u304b\u3089\u3068\u3044\u3046\u6761\u4ef6\u3067\u629c\u304d\u51fa\u3057\u3066\u3044\u308b\u3002<\/p>\n<\/p>\n<p>\u304b\u306a\u308a\u8907\u96d1\u3060\u304c\u3001\u3053\u308c\u306762\u7cfb\u7d71\u306e\u6bce\u6642\u306e\u51fa\u767a\u3059\u308b\u6642\u523b\u306e\u66f8\u304b\u308c\u305f\u884c\u3060\u3051\u629c\u304d\u51fa\u305b\u305f\u3002<\/p>\n<p>103\u7cfb\u7d71\u306e\u3068\u304d\u306f2\u756a\u76ee\u306e\u8868\u306b\u3042\u308b\u304b\u3089\u3001\u6700\u521d\u306e[1]\u3092[2]\u306b\u66f8\u304d\u63db\u3048\u308c\u3070\u3044\u3044\u3002<\/p>\n<p>\u629c\u304d\u51fa\u3057\u305f\u30c7\u30fc\u30bf\u306f&#8221;lines[]&#8221;\u3068\u66f8\u3044\u305f\u304b\u3089\u3001$res-&gt;{&#8220;lines&#8221;}\u306b\u6761\u4ef6\u3092\u6e80\u305f\u3059\u8981\u7d20\u306b\u3064\u3044\u3066=&gt;\u306e\u5f8c\u308d\u306b\u793a\u3057\u305f\u6761\u4ef6\u3067\u51e6\u7406\u3055\u308c\u305f\u3082\u306e\u304c\u51fa\u3066\u304f\u308b\u3002<\/p>\n<p>=&gt;\u4ee5\u964d\u306b\u306fscraper{\u2026}\u3067\u4f5c\u3089\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3001\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3001\u305d\u3057\u3066&#8221;TEXT&#8221;\u3067\u30c6\u30ad\u30b9\u30c8\u3001&#8221;@href&#8221;\u3067\u5c5e\u6027\u3060\u3068\u304b\u304c\u53d6\u308a\u51fa\u305b\u308b\u3002<\/p>\n<p>\u3044\u308d\u3044\u308d\u7d30\u304b\u3044\u7d30\u5de5\u3092XPath\u3067\u66f8\u3044\u3066\u3042\u308b\u304c\u3001\u304a\u304a\u3056\u3063\u3071\u306b\u629c\u304d\u51fa\u3057\u3066\u7d30\u304b\u304f\u9078\u3073\u51fa\u3059\u306e\u306fPerl\u3067\u3084\u308b\u3068\u3044\u3046\u306e\u3082\u3088\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<p>XPath\u306f\u78ba\u304b\u306b\u3044\u308d\u3044\u308d\u8868\u73fe\u3067\u304d\u308b\u3051\u3069\u3001\u7d30\u304b\u3044\u4e8b\u3092\u3059\u308b\u306e\u306f\u3081\u3093\u3069\u304f\u3055\u3044\u3002\u304a\u304a\u3056\u3063\u3071\u306bCSS\u30bb\u30ec\u30af\u30bf\u3067\u629c\u304d\u51fa\u3057\u3066\u3057\u307e\u3048\u3070\u697d\u306a\u306e\u3082\u78ba\u304b\u306a\u8a71\u3060\u3002<\/p>\n<hr \/>\n<p>\u3053\u3093\u306a\u98a8\u306b\u3057\u3066HTML\u304b\u3089\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u3092\u629c\u304d\u51fa\u3057\u3066\u51e6\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u308f\u3051\u3060\u3002<\/p>\n<p>\u76ee\u3067\u898b\u3066\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u3092\u898b\u3064\u3051\u308b\u306e\u306b\u6bd4\u3079\u308b\u3068\u3001\u3069\u3053\u306b\u3042\u308b\u304b\u63a2\u3057\u3066\u6307\u5b9a\u3059\u308b\u306e\u306b\u306f\u624b\u9593\u304c\u304b\u304b\u308b\u3002<\/p>\n<p>\u3057\u304b\u3057\u4e00\u5ea6\u6307\u5b9a\u3059\u308c\u3070\u3042\u3068\u306f\u81ea\u52d5\u3067\u629c\u304d\u51fa\u3057\u3066\u304f\u308c\u308b\u306e\u306f\u4fbf\u5229\u3060\u3057\u9593\u9055\u3048\u304c\u306a\u3044\u3002<\/p>\n<p>\u5b9f\u306b\u30b9\u30af\u30e9\u30a4\u30d4\u30f3\u30b0\u306e\u610f\u7fa9\u306f\u305d\u3053\u306a\u3093\u3058\u3083\u306a\u3044\u304b\u306a\u3068\u601d\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u672c\u5f53\u306f\u51e6\u7406\u306b\u4fbf\u5229\u306a\u3088\u3046\u306bXML\u3068\u304b\u3067\u914d\u5e03\u3057\u3066\u304f\u308c\u308c\u3070\u3046\u308c\u3057\u3044\u3051\u3069\u3001\u306a\u304b\u306a\u304b\u305d\u3093\u306a\u6c17\u306e\u5229\u3044\u305f\u30b5\u30fc\u30d3\u30b9\u306f\u306a\u3044\u3002<\/p>\n<p>\u3051\u3069\u3001\u4eba\u304c\u76ee\u3067\u898b\u308b\u305f\u3081\u306b\u306f\u4fbf\u5229\u306a\u3082\u306e\u304c\u305f\u304f\u3055\u3093\u3042\u308b\u3002\u305d\u308c\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u4e0a\u624b\u304f\u51e6\u7406\u3067\u304d\u308c\u3070\u5f97\u3089\u308c\u308b\u30c7\u30fc\u30bf\u306e\u5e45\u306f\u5e83\u304c\u308b\u3002<\/p>\n<p>\u305d\u3046\u3044\u3046\u3053\u3068\u3067\u3059\u3088\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u304a\u3068\u3068\u3044\u304b\u3089\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3060\u3068\u304b\u8a00\u3063\u3066\u308b\u3051\u3069\u3001Web\u30b5\u30a4\u30c8\u306eHTML\u3092\u89e3\u6790\u3057\u3066\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u3092\u53d6\u3063\u3066\u304f\u308b\u3053\u3068\u306e\u3053\u3068\u3067\u3042\u308b\u3002 \u884c\u5100\u304c\u60aa\u3044\u65b9\u6cd5\u3060\u304c\u3001HTML\u3092\u89e3\u6790\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u5f97\u3089\u308c\u308b\u30c7\u30fc\u30bf\u306f\u591a\u3044\u3002 \u50d5\u304c\u5b9f\u969b\u306b\u8fd1\u9244\u306eNext [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2384","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/2384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2384"}],"version-history":[{"count":0,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/2384\/revisions"}],"wp:attachment":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}