1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2022-03-29 12:55:24 +08:00
parent 2b0511d272
commit b84ae535b7
3973 changed files with 51044 additions and 105065 deletions

View File

@ -8,5 +8,6 @@ echo "
pause
git add .
git commit -m "update"
git gc
git push
pause

View File

@ -34,7 +34,6 @@ def parse_proble_set(problemSet):
continue
def construct_url(problemTitle):
# url = "https://leetcode-cn.com/problems/"+ problemTitle + "/description/"
url = "https://leetcode-cn.com/problems/"+ problemTitle + "/"
# print(url)
get_proble_content(url,problemTitle)
@ -120,11 +119,11 @@ def saveJSON(data, filename):
def main():
url = "https://leetcode-cn.com/api/problems/all/"
html = json.loads(get_proble_set(url))
problemset = html["stat_status_pairs"]
saveJSON(html, "[cn]json1-origin-data.json")
saveJSON(problemset, "[cn]json2-problemset.json")
saveJSON(html, "origin-data.json")
# problemset = json.load(open("[cn]json2-problemset.json", 'r', encoding='utf-8'))
# html = json.load(open("origin-data.json", 'r', encoding='utf-8'))
problemset = html["stat_status_pairs"]
parse_proble_set(problemset)

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ def parse_proble_set(problemSet):
for i in range(len(problemSet)):
# for i in range(930, len(problemSet)):
title = problemSet[i]["stat"]["question__title_slug"]
if os.path.exists("[no content]{}.json".format(title)) or os.path.exists("{}.json".format(title)):
if os.path.exists("originData/[no content]{}.json".format(title)) or os.path.exists("originData/{}.json".format(title)):
print(i, "has been parsed.")
# print("The question has been parsed: {}".format(title))
continue
@ -31,7 +31,6 @@ def parse_proble_set(problemSet):
time.sleep(1)
t =threading.Thread(target=construct_url,args=(title,))
t.start()
print(i, "is done.")
continue
@ -85,13 +84,13 @@ def get_proble_content(problemUrl,title):
response = requests.post(url,data = dumpJsonData, headers = headers,cookies = cookies)
dictInfo = json.loads(response.text)
if dictInfo["data"]["question"].get("content") is not None:
saveJSON(dictInfo, title + ".json")
saveJSON(dictInfo, "originData/" + title + ".json")
content = dictInfo["data"]["question"]["content"]
save_problem(title,content)
save_problem("problem/" + title, content)
# soup = BeautifulSoup(content, 'lxml')
# save_problem(title,soup.prettify())
else:
saveJSON(dictInfo, "[no content]" + title + ".json")
saveJSON(dictInfo, "originData/[no content]" + title + ".json")
# print("no content")
except Exception as e:
print("[error] ", e, problemUrl)
@ -103,11 +102,11 @@ def saveJSON(data, filename):
def main():
url = "https://leetcode.com/api/problems/all/"
html = json.loads(get_proble_set(url))
problemset = html["stat_status_pairs"]
saveJSON(html, "[en]json1-origin-data.json")
saveJSON(problemset, "[en]json2-problemset.json")
saveJSON(html, "origin-data.json")
# problemset = json.load(open("[en]json2-problemset.json", 'r', encoding='utf-8'))
# html = json.load(open("origin-data.json", 'r', encoding='utf-8'))
problemset = html["stat_status_pairs"]
parse_proble_set(problemset)
@ -115,5 +114,9 @@ if __name__=='__main__':
folderName = "leetcode"
if not os.path.exists(folderName):
os.mkdir(folderName)
if not os.path.exists(folderName + "/originData"):
os.mkdir(folderName + "/originData")
if not os.path.exists(folderName + "/problem"):
os.mkdir(folderName + "/problem")
os.chdir(folderName)
main()

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More