pal-crawl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +4 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/eslint.config.mjs +5 -0
- package/package.json +32 -0
- package/renovate.json +5 -0
- package/src/config.ts +5 -0
- package/src/index.ts +1 -0
- package/src/pal.ts +77 -0
- package/tsconfig.json +14 -0
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Doyeon Kim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# 국회 입법예고 크롤러
|
|
2
|
+
|
|
3
|
+
[](#license)
|
|
4
|
+
[](https://github.com/vientorepublic/pal-crawl)
|
|
5
|
+
[](https://github.com/vientorepublic/pal-crawl)
|
|
6
|
+
|
|
7
|
+
국회입법예고(pal.assembly.go.kr)의 진행 중인 입법 예고를 크롤링 하는 Typescript 구현체
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pal-crawl",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "국회입법예고(pal.assembly.go.kr)의 진행 중인 입법 예고 크롤러",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "vientorepublic",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"lint": "eslint \"src/**/*.ts\" --fix",
|
|
11
|
+
"format": "prettier --write \"src/**/*.ts\""
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/vientorepublic/pal-crawl.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/vientorepublic/pal-crawl/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/vientorepublic/pal-crawl#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"axios": "^1.7.9",
|
|
23
|
+
"cheerio": "^1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/cheerio": "^0.22.35",
|
|
27
|
+
"@eslint/js": "^9.18.0",
|
|
28
|
+
"eslint": "^9.18.0",
|
|
29
|
+
"prettier": "^3.4.2",
|
|
30
|
+
"typescript-eslint": "^8.20.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/renovate.json
ADDED
package/src/config.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PalCrawl } from './pal';
|
package/src/pal.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import axios, { isAxiosError } from 'axios';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
import { Config } from './config';
|
|
4
|
+
|
|
5
|
+
export interface ITableData {
|
|
6
|
+
num: number;
|
|
7
|
+
subject: string;
|
|
8
|
+
proposerCategory: string;
|
|
9
|
+
committee: string;
|
|
10
|
+
numComments: number;
|
|
11
|
+
link: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class PalCrawl {
|
|
15
|
+
public async getPalHTML(): Promise<string> {
|
|
16
|
+
try {
|
|
17
|
+
const res = await axios.get<string>(Config.URL, {
|
|
18
|
+
baseURL: Config.DOMAIN,
|
|
19
|
+
headers: {
|
|
20
|
+
'User-Agent': Config.UserAgent,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return res.data;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (isAxiosError(err) && err.response) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Invalid response: ${err.response.status} ${err.response.statusText}`,
|
|
28
|
+
);
|
|
29
|
+
} else {
|
|
30
|
+
if (err instanceof Error) {
|
|
31
|
+
throw new Error(err.message);
|
|
32
|
+
} else {
|
|
33
|
+
console.error(err);
|
|
34
|
+
throw new Error('Unknown Error');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public parseTable(html: string): ITableData[] {
|
|
41
|
+
const $ = cheerio.load(html);
|
|
42
|
+
const body = $('body');
|
|
43
|
+
const table = body.find('table > tbody > tr');
|
|
44
|
+
const output: ITableData[] = [];
|
|
45
|
+
table.map((i, el) => {
|
|
46
|
+
const subject = $(el).find('td.td_block > a.board_subject').text().trim();
|
|
47
|
+
if (subject) {
|
|
48
|
+
const link = $(el).find('td.td_block > a.board_subject').attr('href');
|
|
49
|
+
const numComments = Number(
|
|
50
|
+
$(el).find('td:nth-child(8)').text().replace(',', '').trim(),
|
|
51
|
+
);
|
|
52
|
+
const proposerCategory = $(el).find('td:nth-child(3)').text().trim();
|
|
53
|
+
const committee = $(el).find('td:nth-child(4)').text().trim();
|
|
54
|
+
const num = Number($(el).find('td:nth-child(1)').text().trim());
|
|
55
|
+
let boardLink = '';
|
|
56
|
+
if (link) {
|
|
57
|
+
boardLink = Config.DOMAIN + link;
|
|
58
|
+
}
|
|
59
|
+
output.push({
|
|
60
|
+
num,
|
|
61
|
+
subject,
|
|
62
|
+
proposerCategory,
|
|
63
|
+
committee,
|
|
64
|
+
numComments,
|
|
65
|
+
link: boardLink,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return output;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public async get(): Promise<void> {
|
|
73
|
+
const html = await this.getPalHTML();
|
|
74
|
+
const table = this.parseTable(html);
|
|
75
|
+
console.log(table);
|
|
76
|
+
}
|
|
77
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "CommonJS",
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"sourceMap": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"esModuleInterop": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*"],
|
|
13
|
+
"exclude": ["node_modules", "dist", "test", "example", "**/node_modules/*"]
|
|
14
|
+
}
|