0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Node.js: Yahoo 郵便番号検索API の使い方

Posted at

参考ページ
郵便番号検索API

get_address.js
#! /usr/bin/node
// ---------------------------------------------------------------
//	get_address.js
//
//					Jul/31/2022
//
// ---------------------------------------------------------------
'use strict'
import * as https from "https"
import * as dotenv from "dotenv"

console.error ("*** 開始 ***")
dotenv.config()
const APPID = `${process.env.APPID}`

const code_zip = process.argv[2]
console.log(code_zip)


const url_base = 'https://map.yahooapis.jp/search/zip/V1/zipCodeSearch'
const url = url_base + "?query=" + code_zip + "&output=json"

const headers = {
		"Content-Type": "application/json",
		"User-Agent": "Yahoo AppID: " + APPID
	}

const options = {"headers": headers}

const req = https.get(url, options, res => {
	console.log(`statusCode: ${res.statusCode}`)

	res.on('data', dd => {
//	process.stdout.write(dd)
	const dict_aa = JSON.parse (dd)
	console.log(dict_aa['Feature'][0]['Property']['Address'])
	console.error ("*** 終了 ***")
	})
})

req.on('error', error => {
	console.error(error)
})

req.end()

// ---------------------------------------------------------------
package.json
{
  "type": "module"
}
.env
APPID = 'dj0zaiZpPW9NN3F****'

実行例

./get_address.js 131-8634
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?