forked from sjs7007/all_leetcode_questions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_all_questions.py
44 lines (28 loc) · 880 Bytes
/
export_all_questions.py
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
34
35
36
37
38
39
40
41
42
43
44
import requests
from bs4 import BeautifulSoup
def update_question_links(question_links):
with open('question_links.txt') as f:
links = f.read()
links = links.split('\n')
for each in links:
if '/problems/' in each:
question_links.append(each)
def get_question(question_link):
resp = requests.get(question_link)
soup = BeautifulSoup(resp.text, 'html.parser')
print '------------------------------'
print soup.title.string.split('|')[0]
print '------------------------------'
return soup.find_all('meta')[1].find_all('meta')[1]['content']
def main():
question_links = []
update_question_links(question_links)
for each_question_link in question_links:
try:
print get_question(each_question_link)
print '------------------------------'
except:
continue
if __name__=='__main__':
print '\n'
main()