GetQuestion¶
Query individual question’s information such as the body, test cases, constraints, hints, code stubs, and company tags using the GetQuestion
class:
from leetscrape import GetQuestion
# Get the question body
question = GetQuestion(titleSlug="two-sum").scrape()
This returns a Question
object with the following attributes:
question.QID # Question ID
question.title # Question title
question.titleSlug # Question title slug
question.difficulty # Question difficulty
question.Hints # Question hints
question.Companies # Question companies
question.topics # Question topic tags
question.SimilarQuestions # Similar questions ids
question.Code # Code stubs
question.Body # Question body / problem statement
question.isPaidOnly # Whether the question is only available to premium users of Leetcode
A class to acquire the statement, constraints, hints, basic test cases, related questions, and code stubs of the given question.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
titleSlug |
str
|
The title slug of the question. |
required |
Source code in src/leetscrape/question.py
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
scrape()
¶
This method calls the Leetcode graphql api to query for the hints, companyTags (currently returning null as this is a premium feature), code snippets, and content of the question.
Raises:
Type | Description |
---|---|
ValueError
|
When the connection to Leetcode’s graphql api is not established. |
Returns:
Name | Type | Description |
---|---|---|
QuestionInfo |
Question
|
Contains the QID, titleSlug, Hints, Companies, Similar Questions, Code stubs, and the body of the question. |