-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.ts
33 lines (28 loc) · 1008 Bytes
/
github.ts
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
import { DOMParser } from './deps.ts';
const url = 'https://github.com/trending';
let url_list: string[] = [];
// let title_list: string[] = [];
const url_prefix = 'https://github.com/'
const res = await fetch(url);
const html = await res.text();
const doc = new DOMParser().parseFromString(html, 'text/html');
const ref = doc?.querySelector('#js-pjax-container>.position-relative>.Box');
export const scrapingRepo = (): string[] => {
const repositories = ref?.querySelectorAll('div>.Box-row>h1>a');
if (repositories) {
for(const repositoty of repositories) {
url_list.push(url_prefix + repositoty.textContent.replace('\n\n', '').replace(/\s+/g, '').trim())
}
}
return url_list;
}
// 多分いらない
// export const scrapingTitle = (): string[] => {
// const titles = ref?.querySelectorAll('div>.Box-row>p');
// if (titles) {
// for(const title of titles) {
// title_list.push(title.textContent.trim().replace("\n", ""))
// }
// }
// return title_list
// }