Skip to content

爬虫修复 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/LeetCodeProvider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const request = require("request");
const Iconv = require("iconv-lite");
const cheerio = require("cheerio");

Expand All @@ -21,8 +20,10 @@ module.exports = LeetCodeProvider = {
.load(sHtml)(QUESTION_DOM_SELECTOR)
.each((idx, ele) => titles.push(ele.attribs["title"]));
Logger.success("获取问题列表成功");

return titles.filter((name) => !name.endsWith(ENGLISH_MARKDOWN_SIGN));
/**
* 由于QUESTION_DOM_SELECTOR 所选择的结构包含非问题标签,获取title会是undefined,在此需将其过滤掉
*/
return titles.filter(Boolean).filter((name) => !name.endsWith(ENGLISH_MARKDOWN_SIGN));
})
.catch((error) => {
Logger.error("获取问题列表失败", error);
Expand All @@ -41,3 +42,5 @@ module.exports = LeetCodeProvider = {
});
},
};

LeetCodeProvider.getProblemsTitle()
2 changes: 1 addition & 1 deletion scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
/**
* 抓取页面问题内容的dom元素选择器
*/
QUESTION_DOM_SELECTOR: ".js-navigation-item .content .js-navigation-open",
QUESTION_DOM_SELECTOR: ".position-relative.js-navigation-item .js-navigation-open",

/**
* markdwon下载地址
Expand Down
9 changes: 6 additions & 3 deletions scripts/generateleetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const {
SUPPORT_LANGUAGE,
DB_JSON_OUTPUT_DIR,
RAW_MARKDOWN_OUTPUT_DIR,
ENGLISH_MARKDOWN_SIGN,
} = require("./constants");
} = require('./constants')




const genertateLeetcodeToJson = () => {
console.time("genertateLeetcodeToJson");
Expand Down Expand Up @@ -46,8 +48,9 @@ const genertateLeetcodeToJson = () => {
});
});
markdown.replace(Utils.getSatelliteDataReg().pre, (noUseMatch, $1) => {

preKnowledge.push({
text: $1,
text: $1.replace('-',''),
link: null,
color: "red",
});
Expand Down
Loading