pal-crawl 1.0.0 → 1.0.1

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.
@@ -0,0 +1,5 @@
1
+ export declare enum Config {
2
+ DOMAIN = "https://pal.assembly.go.kr",
3
+ URL = "/napal/lgsltpa/lgsltpaOngoing/list.do",
4
+ UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
5
+ }
package/dist/config.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Config = void 0;
4
+ var Config;
5
+ (function (Config) {
6
+ Config["DOMAIN"] = "https://pal.assembly.go.kr";
7
+ Config["URL"] = "/napal/lgsltpa/lgsltpaOngoing/list.do";
8
+ Config["UserAgent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
9
+ })(Config || (exports.Config = Config = {}));
10
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,+CAAqC,CAAA;IACrC,uDAA6C,CAAA;IAC7C,uIAA6H,CAAA;AAC/H,CAAC,EAJW,MAAM,sBAAN,MAAM,QAIjB"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PalCrawl = void 0;
4
+ var pal_1 = require("./pal");
5
+ Object.defineProperty(exports, "PalCrawl", { enumerable: true, get: function () { return pal_1.PalCrawl; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6BAAiC;AAAxB,+FAAA,QAAQ,OAAA"}
package/dist/pal.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface ITableData {
2
+ num: number;
3
+ subject: string;
4
+ proposerCategory: string;
5
+ committee: string;
6
+ numComments: number;
7
+ link: string;
8
+ }
9
+ export declare class PalCrawl {
10
+ getPalHTML(): Promise<string>;
11
+ parseTable(html: string): ITableData[];
12
+ get(): Promise<void>;
13
+ }
package/dist/pal.js ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PalCrawl = void 0;
37
+ const axios_1 = __importStar(require("axios"));
38
+ const cheerio = __importStar(require("cheerio"));
39
+ const config_1 = require("./config");
40
+ class PalCrawl {
41
+ async getPalHTML() {
42
+ try {
43
+ const res = await axios_1.default.get(config_1.Config.URL, {
44
+ baseURL: config_1.Config.DOMAIN,
45
+ headers: {
46
+ 'User-Agent': config_1.Config.UserAgent,
47
+ },
48
+ });
49
+ return res.data;
50
+ }
51
+ catch (err) {
52
+ if ((0, axios_1.isAxiosError)(err) && err.response) {
53
+ throw new Error(`Invalid response: ${err.response.status} ${err.response.statusText}`);
54
+ }
55
+ else {
56
+ if (err instanceof Error) {
57
+ throw new Error(err.message);
58
+ }
59
+ else {
60
+ console.error(err);
61
+ throw new Error('Unknown Error');
62
+ }
63
+ }
64
+ }
65
+ }
66
+ parseTable(html) {
67
+ const $ = cheerio.load(html);
68
+ const body = $('body');
69
+ const table = body.find('table > tbody > tr');
70
+ const output = [];
71
+ table.map((i, el) => {
72
+ const subject = $(el).find('td.td_block > a.board_subject').text().trim();
73
+ if (subject) {
74
+ const link = $(el).find('td.td_block > a.board_subject').attr('href');
75
+ const numComments = Number($(el).find('td:nth-child(8)').text().replace(',', '').trim());
76
+ const proposerCategory = $(el).find('td:nth-child(3)').text().trim();
77
+ const committee = $(el).find('td:nth-child(4)').text().trim();
78
+ const num = Number($(el).find('td:nth-child(1)').text().trim());
79
+ let boardLink = '';
80
+ if (link) {
81
+ boardLink = config_1.Config.DOMAIN + link;
82
+ }
83
+ output.push({
84
+ num,
85
+ subject,
86
+ proposerCategory,
87
+ committee,
88
+ numComments,
89
+ link: boardLink,
90
+ });
91
+ }
92
+ });
93
+ return output;
94
+ }
95
+ async get() {
96
+ const html = await this.getPalHTML();
97
+ const table = this.parseTable(html);
98
+ console.log(table);
99
+ }
100
+ }
101
+ exports.PalCrawl = PalCrawl;
102
+ //# sourceMappingURL=pal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pal.js","sourceRoot":"","sources":["../src/pal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;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,IAAI,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF;AA/DD,4BA+DC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pal-crawl",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "국회입법예고(pal.assembly.go.kr)의 진행 중인 입법 예고 크롤러",
5
5
  "license": "MIT",
6
6
  "author": "vientorepublic",
package/src/config.ts DELETED
@@ -1,5 +0,0 @@
1
- export enum Config {
2
- DOMAIN = 'https://pal.assembly.go.kr',
3
- URL = '/napal/lgsltpa/lgsltpaOngoing/list.do',
4
- UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
5
- }
package/src/pal.ts DELETED
@@ -1,77 +0,0 @@
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
- }
File without changes