{"id":529,"date":"2018-03-05T21:22:20","date_gmt":"2018-03-05T12:22:20","guid":{"rendered":"https:\/\/yuis-programming.com\/?p=529"},"modified":"2018-03-01T02:24:36","modified_gmt":"2018-02-28T17:24:36","slug":"townwork","status":"publish","type":"post","link":"https:\/\/yuis-programming.com\/?p=529","title":{"rendered":"\u30bf\u30a6\u30f3\u30ef\u30fc\u30af\u304b\u3089\u6848\u4ef6\u306e\u4ea4\u901a\u60c5\u5831\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u6700\u5bc4\u308a\u99c5\u304b\u3089\u306e\u8ddd\u96e2\u3092\u51fa\u529b\u3059\u308b"},"content":{"rendered":"<p>\u30bf\u30a6\u30f3\u30ef\u30fc\u30af\u898b\u3066\u3066\u3001\u3053\u306e\u99c5\u3063\u3066\u6700\u5bc4\u308a\u99c5(\u81ea\u5206\u306e\u5730\u57df)\u304b\u3089\u3069\u308c\u304f\u3089\u3044\u304b\u304b\u308b\u3093\u3060\u308d\u3046\u2026\u3068\u601d\u3046\u3053\u3068\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u50d5\u306f\u6771\u4eac\u4f4f\u307f\u306f\u3058\u3081\u30661\u30f6\u6708\u3057\u304b\u305f\u3063\u3066\u306a\u304f\u3066\u3001\u6771\u4eac\u306e\u99c5\u306e\u3053\u3068\u306a\u3093\u304b\u3055\u3063\u3071\u308a\u3067\u3001\u6709\u540d\u306a\u99c5\u304c\u3069\u3053\u3089\u3078\u3093\u306b\u3042\u308b\u304b\u3001\u3069\u308c\u304f\u3089\u3044\u304b\u304b\u308b\u304b\u3001\u306a\u3093\u3066\u5168\u304f\u308f\u304b\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u30bf\u30a6\u30f3\u30ef\u30fc\u30af\u3063\u3066\u3001\u6848\u4ef6\u305d\u308c\u305e\u308c\u306b\u6700\u5bc4\u308a\u99c5\u3068\u304b\u99c5\u304b\u3089\u5f92\u6b69\u4f55\u5206\u3068\u306f\u66f8\u3044\u3066\u3042\u308b\u3051\u3069\u3001\u6700\u5bc4\u308a\u99c5\u3068\u304b\u8fd1\u3044\u306e\u304b\u3068\u304b\u3063\u3066\u308f\u304b\u3089\u306a\u3044\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u307b\u3093\u3068\u306f\u30bf\u30a6\u30f3\u30ef\u30fc\u30af\u5074\u3067\u3001\u6700\u5bc4\u308a\u99c5\u306a\u3093\u304b\u3092\u8a2d\u5b9a\u3057\u3066\u3001\u8fd1\u3044\u9806\u756a\u306b\u30bd\u30fc\u30c8\u3059\u308b\u3068\u304b\u3001\u4f55\u6642\u9593\u304f\u3089\u3044\u3067\u7740\u3051\u308b\u3068\u304b\u8868\u793a\u3059\u308b\u3068\u304b\u5b9f\u88c5\u3059\u308b\u3079\u304d\u3060\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u305d\u3046\u3044\u3046\u6a5f\u80fd\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u3002<\/p>\n<p>Ruby\u3067\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>url\u3092\u3001\u6848\u4ef6\u4e00\u89a7\u306e\u30da\u30fc\u30b8\u306b\u3001<br \/>\n@now_location \u3068 @APIKEY \u306f\u5404\u81ea\u3067\u57cb\u3081\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code>require \"open-uri\"\nrequire \"rubygems\"\nrequire \"nokogiri\"\n\n# \u30bf\u30a6\u30f3\u30ef\u30fc\u30af\u304b\u3089\u6848\u4ef6\u306e\u4ea4\u901a\u60c5\u5831\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b https:\/\/townwork.net\/tokyo\/kwd_0000000018\/\n\nEncoding.default_external = 'UTF-8'\n\nurl = \"https:\/\/townwork.net\/tokyo\/kwd_0000000018\/\"\n\ncharset = nil\nhtml = open(url) do |f|\n  charset = f.charset\n  f.read\nend\ndoc = Nokogiri::HTML.parse(html, nil, charset)\n\n@list=[]\np doc.xpath('\/\/*[@id=\"jsi-content-wrapper\"]\/div[1]\/div[4]\/div[*]\/div\/a\/div\/table\/tbody\/tr[2]\/td\/p\/text()').each{|i|\n  i=i.text ;\n  i=i.gsub(\/\u5f92\u6b69.{1,3}\u5206\/,\"\") ;\n  # p i\n  @list &lt;&lt; i\n}\n# p @list # =&gt; [\"\u56db\u30c4\u8c37\u99c5\", \"\u5927\u68ee\u99c5\", \"\u65b0\u5927\u4e45\u4fdd\u99c5\", \"\u4e2d\u91ce\u99c5\", \"\u98ef\u7530\u6a4b\u99c5\", \"\u516b\u738b\u5b50\u99c5\", \"\u5e9c\u4e2d\u99c5\", \"\u795e\u7530\u99c5\"]\n\n# Google Maps API\u3067\u99c5\u3084\u5834\u6240\u306e2\u70b9\u8ddd\u96e2(km)\u3092\u51fa\u529b\u3059\u308b\n# __END__\nrequire 'net\/http'\nrequire 'json'\n\nEncoding.default_external = 'UTF-8'\n\n@now_location = \"\u685c\u4e0a\u6c34\u99c5\"\n\nif @list\nelse\n@list=\"\n\u516b\u738b\u5b50\u99c5\n\u516b\u738b\u5b50\n\"\n@list=@list.split(\"\\n\").compact.reject(&amp;:empty?)\nend\n\nuntil @list.empty?\n  # puts 1\n  # @location=\"\u516b\u738b\u5b50\"\n  @location = @list.pop\n  @APIKEY = \"\"\n\n  url=\"https:\/\/maps.googleapis.com\/maps\/api\/distancematrix\/json?origins=#{@now_location}&amp;destinations=#{@location}&amp;mode=walking&amp;language=ja&amp;key=#{@APIKEY}\"\n  uri = URI(URI.encode(url))\n  response = Net::HTTP.get(uri)\n  data=JSON.parse(response)\n\n  puts @location + \":\" + km= data['rows'][0]['elements'][0]['distance']['text'] ;\n  # puts @location + \":\" + km= data['rows'][0]['elements'][0]['duration']['text'] ; # =&gt; \u96fb\u8eca\u3067\u306e\u6642\u9593\u3067\u306f\u306a\u304f\u3001\u5f92\u6b69\u3067\u306e\u6642\u9593\uff1f\u306a\u306e\u3067\u4f7f\u3048\u306a\u3044\u3002\n\nend\n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30bf\u30a6\u30f3\u30ef\u30fc\u30af\u898b\u3066\u3066\u3001\u3053\u306e\u99c5\u3063\u3066\u6700\u5bc4\u308a\u99c5(\u81ea\u5206\u306e\u5730\u57df)\u304b\u3089\u3069\u308c\u304f\u3089\u3044\u304b\u304b\u308b\u3093\u3060\u308d\u3046\u2026\u3068\u601d\u3046\u3053\u3068\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"acf":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s8Rxwo-townwork","_links":{"self":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/529"}],"collection":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=529"}],"version-history":[{"count":0,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/529\/revisions"}],"wp:attachment":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}