mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 14:32:54 +08:00
update
This commit is contained in:
1
get.bat
1
get.bat
@@ -8,5 +8,6 @@ echo "
|
|||||||
pause
|
pause
|
||||||
git add .
|
git add .
|
||||||
git commit -m "update"
|
git commit -m "update"
|
||||||
|
git gc
|
||||||
git push
|
git push
|
||||||
pause
|
pause
|
@@ -34,7 +34,6 @@ def parse_proble_set(problemSet):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
def construct_url(problemTitle):
|
def construct_url(problemTitle):
|
||||||
# url = "https://leetcode-cn.com/problems/"+ problemTitle + "/description/"
|
|
||||||
url = "https://leetcode-cn.com/problems/"+ problemTitle + "/"
|
url = "https://leetcode-cn.com/problems/"+ problemTitle + "/"
|
||||||
# print(url)
|
# print(url)
|
||||||
get_proble_content(url,problemTitle)
|
get_proble_content(url,problemTitle)
|
||||||
@@ -120,11 +119,11 @@ def saveJSON(data, filename):
|
|||||||
def main():
|
def main():
|
||||||
url = "https://leetcode-cn.com/api/problems/all/"
|
url = "https://leetcode-cn.com/api/problems/all/"
|
||||||
html = json.loads(get_proble_set(url))
|
html = json.loads(get_proble_set(url))
|
||||||
problemset = html["stat_status_pairs"]
|
saveJSON(html, "origin-data.json")
|
||||||
saveJSON(html, "[cn]json1-origin-data.json")
|
|
||||||
saveJSON(problemset, "[cn]json2-problemset.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)
|
parse_proble_set(problemset)
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
21
leetcode.py
21
leetcode.py
@@ -22,7 +22,7 @@ def parse_proble_set(problemSet):
|
|||||||
for i in range(len(problemSet)):
|
for i in range(len(problemSet)):
|
||||||
# for i in range(930, len(problemSet)):
|
# for i in range(930, len(problemSet)):
|
||||||
title = problemSet[i]["stat"]["question__title_slug"]
|
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(i, "has been parsed.")
|
||||||
# print("The question has been parsed: {}".format(title))
|
# print("The question has been parsed: {}".format(title))
|
||||||
continue
|
continue
|
||||||
@@ -31,7 +31,6 @@ def parse_proble_set(problemSet):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
t =threading.Thread(target=construct_url,args=(title,))
|
t =threading.Thread(target=construct_url,args=(title,))
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
print(i, "is done.")
|
print(i, "is done.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -85,13 +84,13 @@ def get_proble_content(problemUrl,title):
|
|||||||
response = requests.post(url,data = dumpJsonData, headers = headers,cookies = cookies)
|
response = requests.post(url,data = dumpJsonData, headers = headers,cookies = cookies)
|
||||||
dictInfo = json.loads(response.text)
|
dictInfo = json.loads(response.text)
|
||||||
if dictInfo["data"]["question"].get("content") is not None:
|
if dictInfo["data"]["question"].get("content") is not None:
|
||||||
saveJSON(dictInfo, title + ".json")
|
saveJSON(dictInfo, "originData/" + title + ".json")
|
||||||
content = dictInfo["data"]["question"]["content"]
|
content = dictInfo["data"]["question"]["content"]
|
||||||
save_problem(title,content)
|
save_problem("problem/" + title, content)
|
||||||
# soup = BeautifulSoup(content, 'lxml')
|
# soup = BeautifulSoup(content, 'lxml')
|
||||||
# save_problem(title,soup.prettify())
|
# save_problem(title,soup.prettify())
|
||||||
else:
|
else:
|
||||||
saveJSON(dictInfo, "[no content]" + title + ".json")
|
saveJSON(dictInfo, "originData/[no content]" + title + ".json")
|
||||||
# print("no content")
|
# print("no content")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[error] ", e, problemUrl)
|
print("[error] ", e, problemUrl)
|
||||||
@@ -103,11 +102,11 @@ def saveJSON(data, filename):
|
|||||||
def main():
|
def main():
|
||||||
url = "https://leetcode.com/api/problems/all/"
|
url = "https://leetcode.com/api/problems/all/"
|
||||||
html = json.loads(get_proble_set(url))
|
html = json.loads(get_proble_set(url))
|
||||||
problemset = html["stat_status_pairs"]
|
saveJSON(html, "origin-data.json")
|
||||||
saveJSON(html, "[en]json1-origin-data.json")
|
|
||||||
saveJSON(problemset, "[en]json2-problemset.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)
|
parse_proble_set(problemset)
|
||||||
|
|
||||||
|
|
||||||
@@ -115,5 +114,9 @@ if __name__=='__main__':
|
|||||||
folderName = "leetcode"
|
folderName = "leetcode"
|
||||||
if not os.path.exists(folderName):
|
if not os.path.exists(folderName):
|
||||||
os.mkdir(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)
|
os.chdir(folderName)
|
||||||
main()
|
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
Reference in New Issue
Block a user