@@ -34,7 +34,7 @@ def parse_proble_set(problemSet):
3434 continue
3535
3636def construct_url (problemTitle ):
37- url = "https://leetcode-cn.com /problems/" + problemTitle + "/"
37+ url = "https://leetcode.cn /problems/" + problemTitle + "/"
3838 # print(url)
3939 get_proble_content (url ,problemTitle )
4040
@@ -49,7 +49,7 @@ def save_problem(title,content, editorType = ""):
4949
5050def get_proble_content (problemUrl ,title ):
5151 # 随便请求一个页面,获取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 "}''' )
5353 setCookie = response .headers ["set-cookie" ]
5454 # print(setCookie)
5555 '''
@@ -61,7 +61,7 @@ def get_proble_content(problemUrl,title):
6161 pattern = re .compile (".*?csrftoken=(.*?);.*?" ,re .S )
6262 csrftoken = re .search (pattern , setCookie )
6363 # print(csrftoken.group(1))
64- url = "https://leetcode-cn.com /graphql"
64+ url = "https://leetcode.cn /graphql"
6565 data = {
6666 "operationName" :"questionData" ,
6767 "variables" :{"titleSlug" :title },
@@ -71,7 +71,7 @@ def get_proble_content(problemUrl,title):
7171 'x-csrftoken' : csrftoken .group (1 ),
7272 'referer' :problemUrl ,
7373 'content-type' :'application/json' ,
74- 'origin' :'https://leetcode-cn.com ' ,
74+ 'origin' :'https://leetcode.cn ' ,
7575 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'
7676 }
7777 cookies = {
@@ -117,7 +117,7 @@ def saveJSON(data, filename):
117117 json .dump (data , f , ensure_ascii = False , indent = 4 )
118118
119119def main ():
120- url = "https://leetcode-cn.com /api/problems/all/"
120+ url = "https://leetcode.cn /api/problems/all/"
121121 html = json .loads (get_proble_set (url ))
122122 saveJSON (html , "origin-data.json" )
123123
0 commit comments