-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchJCN.js
81 lines (67 loc) · 4.05 KB
/
searchJCN.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { HTMLParser } from "https://js.sabae.cc/HTMLParser.js";
const getToken = async () => {
const url = "https://www.houjin-bangou.nta.go.jp";
const text = await (await fetch(url)).text();
await Deno.writeTextFile("_getToken.html", text);
const dom = HTMLParser.parse(text);
const token = dom.querySelector("form#appForm input").getAttribute("value");
console.log(token);
return token;
};
//const token = getToken(); // NG
const token = "fb932017-f90a-4c02-ba99-e40775283bdd";
/*
<form id="appForm" action="/index.html" method="post"><div><input type="hidden" name="jp.go.nta.houjin_bangou.framework.web.common.CNSFWTokenProcessor.request.token" value="d003a9c2-9495-4963-b78c-6d87189855c2"/></div>
*/
const fetchHTML = async (name) => {
const body = `jp.go.nta.houjin_bangou.framework.web.common.CNSFWTokenProcessor.request.token=${token}&houzinNmShTypeRbtn=2&houzinNmTxtf=${encodeURIComponent(name)}&_kanaCkbx=on&_noconvCkbx=on&_enCkbx=on&houzinAddrShTypeRbtn=1&prefectureLst=&houzinNoShTyoumeSts=0&kokugaiTxtf=&zipCdTxtf=&prefectureLstEn=&kokugaiTxtfEn=&houzinNoShSonotaZyoukenSts=0&_houzinKdCkbx=on&_houzinKdCkbx=on&_houzinKdCkbx=on&_houzinKdCkbx=on&_houzinKdCkbx=on&_houzinKdCkbx=on&_houzinKdCkbx=on&_houzinKdCkbx=on&_historyCkbx=on&_hideCkbx=on&closeCkbx=1&_closeCkbx=on&_chgYmdShTargetCkbx=on&chgYmdEyFromLst=000&chgYmdMFromLst=00&chgYmdDFromLst=00&chgYmdEyToLst=000&chgYmdMToLst=00&chgYmdDToLst=00&orderRbtn=1&houzinKdRbtn=0&_historyCkbx=on&orderRbtnEn=1&houzinNoTxtf=&searchFlg=1&preSyousaiScreenId=KJSCR0101010`;
const url = "https://www.houjin-bangou.nta.go.jp/kensaku-kekka.html";
const headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
};
const method = "POST";
const res = await fetch(url, { method, headers, body });
const text = await res.text();
return text;
};
export const searchJCN = async (name) => {
const n = name.indexOf("(");
if (n >= 0) {
name = name.substring(0, n);
}
//const text = await Deno.readTextFile("_searchJCN.html");
const text = await fetchHTML(name);
const dom = HTMLParser.parse(text);
const jcn = dom.querySelector("div.tbl01 tbody th")?.text?.trim();
return jcn;
};
// const name = "jig.jp";
/*
const name = "株式会社京都フィナンシャルグループ";
//const text = await fetchHTML(name);
//await Deno.writeTextFile("_searchJCN.html", text);
const jcn = await searchJCN(name);
console.log(jcn);
*/
/*
<div class="tbl01">
<table class="fixed normal">
<thead>
<tr>
<th class="w18" scope="col">法人番号</th>
<th class="w30" scope="col">商号又は名称</th>
<th class="w37" scope="col">所在地</th>
<th class="w16" scope="col">変更履歴情報等</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
3011101042092
</th>
<td>
<div class="furigana">ジグジェーピー</div>
株式会社jig.jp
</td>
*/