@@ -34,7 +34,7 @@ def parse_proble_set(problemSet):
34
34
continue
35
35
36
36
def construct_url (problemTitle ):
37
- url = "https://leetcode-cn.com /problems/" + problemTitle + "/"
37
+ url = "https://leetcode.cn /problems/" + problemTitle + "/"
38
38
# print(url)
39
39
get_proble_content (url ,problemTitle )
40
40
@@ -49,7 +49,7 @@ def save_problem(title,content, editorType = ""):
49
49
50
50
def get_proble_content (problemUrl ,title ):
51
51
# 随便请求一个页面,获取csrf_token
52
- response = requests .get ('https://leetcode-cn.com /graphql/' , data = '''{"operationName":"userPremiumInfo","variables":{},"query":"query userPremiumInfo {\n userStatus {\n isPremium\n subscriptionPlanType\n __typename\n }\n }\n "}''' )
52
+ response = requests .get ('https://leetcode.cn /graphql/' , data = '''{"operationName":"userPremiumInfo","variables":{},"query":"query userPremiumInfo {\n userStatus {\n isPremium\n subscriptionPlanType\n __typename\n }\n }\n "}''' )
53
53
setCookie = response .headers ["set-cookie" ]
54
54
# print(setCookie)
55
55
'''
@@ -61,7 +61,7 @@ def get_proble_content(problemUrl,title):
61
61
pattern = re .compile (".*?csrftoken=(.*?);.*?" ,re .S )
62
62
csrftoken = re .search (pattern , setCookie )
63
63
# print(csrftoken.group(1))
64
- url = "https://leetcode-cn.com /graphql"
64
+ url = "https://leetcode.cn /graphql"
65
65
data = {
66
66
"operationName" :"questionData" ,
67
67
"variables" :{"titleSlug" :title },
@@ -71,7 +71,7 @@ def get_proble_content(problemUrl,title):
71
71
'x-csrftoken' : csrftoken .group (1 ),
72
72
'referer' :problemUrl ,
73
73
'content-type' :'application/json' ,
74
- 'origin' :'https://leetcode-cn.com ' ,
74
+ 'origin' :'https://leetcode.cn ' ,
75
75
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'
76
76
}
77
77
cookies = {
@@ -117,7 +117,7 @@ def saveJSON(data, filename):
117
117
json .dump (data , f , ensure_ascii = False , indent = 4 )
118
118
119
119
def main ():
120
- url = "https://leetcode-cn.com /api/problems/all/"
120
+ url = "https://leetcode.cn /api/problems/all/"
121
121
html = json .loads (get_proble_set (url ))
122
122
saveJSON (html , "origin-data.json" )
123
123
0 commit comments