-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1cfa3b
commit 00b4bb8
Showing
11 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
KIPALOG_LAST_PAGE=76 | ||
DAYNHAUHOC_LAST_PAGE=1358 | ||
GIAPHIEP_LAST_PAGE=1375 | ||
VIBLOQUESTION_LAST_PAGE=64 | ||
|
||
## For debug | ||
# DAYNHAUHOC_LAST_PAGE=2 | ||
# KIPALOG_LAST_PAGE=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/app.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
app :{ | ||
|
||
}, | ||
kipalogLastPage: process.env.KIPALOG_LAST_PAGE, | ||
daynhauhocLastPage: process.env.DAYNHAUHOC_LAST_PAGE, | ||
giaphiepLastPage: process.env.GIAPHIEP_LAST_PAGE, | ||
vibloquestionLastPage: process.env.VIBLOQUESTION_LAST_PAGE, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const chalk = require('chalk'); | ||
|
||
const { articleModel } = require('../models'); | ||
|
||
const daynhauhocHomePage = 'https://daynhauhoc.com'; | ||
|
||
const type = 'daynhauhoc'; | ||
|
||
const daynhauhocPaginateUrl = (page = 0) => { | ||
return `${daynhauhocHomePage}/latest.json?no_definitions=true&page=${page}`; | ||
} | ||
|
||
const daynhauhocCrawler = async (browser, article) => { | ||
let { id, title, slug, tags } = article; | ||
|
||
if (tags.length !== 0) | ||
tags = tags.map(tag => String(tag).toLocaleLowerCase().trim().replace(' ', '-')).join(';'); | ||
else | ||
tags = 'none'; | ||
|
||
let path = `/t/${slug}/${id}`; | ||
const pageUrl = `${daynhauhocHomePage}${path}`; | ||
console.log(chalk.yellow('Crawling... ') + chalk.green(pageUrl)); | ||
|
||
const page = await browser.newPage(); | ||
await page.setDefaultNavigationTimeout(0); | ||
await page.goto(pageUrl); | ||
|
||
const { htmlContent, textContent } = await page.evaluate(() => { | ||
const raw = document.querySelectorAll('#post_1 > div > div.topic-body.clearfix > div.regular.contents')[0]; | ||
const htmlContent = raw.outerHTML; | ||
const { textContent } = raw; | ||
return { htmlContent, textContent }; | ||
}); | ||
|
||
page.close(); | ||
const articleData = { title, path, tags, htmlContent, textContent, from: `${type}` }; | ||
await articleModel.create(articleData); | ||
return articleData; | ||
} | ||
|
||
module.exports = { | ||
daynhauhocPaginateUrl, | ||
daynhauhocCrawler, | ||
daynhauhocHomePage, | ||
type | ||
} | ||
// max = 1358x20 | ||
// https://daynhauhoc.com/latest.json?no_definitions=true&page=200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// max=1375x20 | ||
// https://api.giaphiep.com/posts?page=1375 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// max=64x20 | ||
// https://viblo.asia/api/questions?feed=newest&limit=20&page=64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,11 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.781568.tgz#4cdca90a952d2c77831096ff6cd32695d8715a04" | ||
integrity sha512-9Uqnzy6m6zEStluH9iyJ3iHyaQziFnMnLeC8vK0eN6smiJmIx7+yB64d67C2lH/LZra+5cGscJAJsNXO+MdPMg== | ||
|
||
dotenv@^8.2.0: | ||
version "8.2.0" | ||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" | ||
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== | ||
|
||
dottie@^2.0.0: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/dottie/-/dottie-2.0.2.tgz#cc91c0726ce3a054ebf11c55fbc92a7f266dd154" | ||
|