获取题目详情
(self, question_title_slug: str, retry: int = 3)
| 135 | return {} |
| 136 | |
| 137 | def get_question_detail(self, question_title_slug: str, retry: int = 3) -> dict: |
| 138 | """获取题目详情""" |
| 139 | form1 = { |
| 140 | "operationName": "globalData", |
| 141 | "query": "query globalData {\n feature {\n questionTranslation\n subscription\n signUp\n " |
| 142 | "discuss\n mockInterview\n contest\n store\n book\n chinaProblemDiscuss\n " |
| 143 | "socialProviders\n studentFooter\n cnJobs\n enableLsp\n enableWs\n " |
| 144 | "enableDebugger\n enableDebuggerAdmin\n enableDarkMode\n tasks\n " |
| 145 | "leetbook\n __typename\n }\n userStatus {\n isSignedIn\n isAdmin\n " |
| 146 | "isStaff\n isSuperuser\n isTranslator\n isPremium\n isVerified\n " |
| 147 | "isPhoneVerified\n isWechatVerified\n checkedInToday\n username\n " |
| 148 | "realName\n userSlug\n groups\n avatar\n optedIn\n " |
| 149 | "requestRegion\n region\n activeSessionId\n permissions\n notificationStatus {\n " |
| 150 | "lastModified\n numUnread\n __typename\n }\n completedFeatureGuides\n " |
| 151 | "useTranslation\n accountStatus {\n isFrozen\n inactiveAfter\n __typename\n " |
| 152 | "}\n __typename\n }\n siteRegion\n chinaHost\n websocketUrl\n userBannedInfo {\n " |
| 153 | "bannedData {\n endAt\n bannedType\n __typename\n }\n __typename\n }\n}\n", |
| 154 | "variables": {}, |
| 155 | } |
| 156 | headers = { |
| 157 | "User-Agent": user_agent, |
| 158 | "Connection": "keep-alive", |
| 159 | "Content-Type": "application/json", |
| 160 | "Referer": "https://leetcode.cn/problems/" + question_title_slug, |
| 161 | "cookie": self.cookie_cn, |
| 162 | } |
| 163 | |
| 164 | form2 = { |
| 165 | "operationName": "questionData", |
| 166 | "variables": {"titleSlug": question_title_slug}, |
| 167 | "query": "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n " |
| 168 | "questionId\n questionFrontendId\n categoryTitle\n boundTopicId\n title\n " |
| 169 | "titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n " |
| 170 | "difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n " |
| 171 | "contributors {\n username\n profileUrl\n avatarUrl\n __typename\n " |
| 172 | "}\n langToValidPlayground\n topicTags {\n name\n slug\n " |
| 173 | "translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n " |
| 174 | "lang\n langSlug\n code\n __typename\n }\n stats\n hints\n " |
| 175 | "solution {\n id\n canSeeDetail\n __typename\n }\n status\n " |
| 176 | "sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n " |
| 177 | "enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n " |
| 178 | "source\n shortDescription\n fullDescription\n bookImgUrl\n " |
| 179 | "pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n " |
| 180 | "isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n " |
| 181 | "exampleTestcases\n __typename\n }\n}\n", |
| 182 | } |
| 183 | for _ in range(max(0, retry) + 1): |
| 184 | try: |
| 185 | requests.post( |
| 186 | url=cn_graph_url, |
| 187 | data=json.dumps(form1), |
| 188 | headers=headers, |
| 189 | timeout=10, |
| 190 | verify=False, |
| 191 | ) |
| 192 | # get question detail |
| 193 | resp = requests.post( |
| 194 | url=cn_graph_url, |