@@ -23,22 +23,28 @@ class SearchModifiers(Enum):
23
23
24
24
class HTMLRequests :
25
25
BASE_URL = 'https://howlongtobeat.com/'
26
- SEARCH_URL = BASE_URL + "search_results.php "
27
- GAME_URL = BASE_URL + "game.php ?id="
26
+ SEARCH_URL = BASE_URL + "search_results"
27
+ GAME_URL = BASE_URL + "game?id="
28
28
29
29
@staticmethod
30
- def send_web_request (game_name : str , search_modifiers : SearchModifiers = SearchModifiers .NONE ):
30
+ def send_web_request (game_name : str , search_modifiers : SearchModifiers = SearchModifiers .NONE , page : int = 1 ):
31
31
"""
32
32
Function that search the game using a normal request
33
33
@param game_name: The original game name received as input
34
34
@param search_modifiers: The "Modifiers" list in "Search Options", allow to show/isolate/hide DLCs
35
+ @param page: The page to explore of the research, unknown if this is actually used
35
36
@return: The HTML code of the research if the request returned 200(OK), None otherwise
36
37
"""
37
38
ua = UserAgent ()
39
+ params = {
40
+ 'page' : str (page )
41
+ }
38
42
headers = {
39
43
'content-type' : 'application/x-www-form-urlencoded' ,
40
44
'accept' : '*/*' ,
41
- 'User-Agent' : ua .random
45
+ 'User-Agent' : ua .random ,
46
+ 'origin' : 'https://howlongtobeat.com' ,
47
+ 'referer' : 'https://howlongtobeat.com/'
42
48
}
43
49
payload = {
44
50
'queryString' : game_name ,
@@ -49,28 +55,38 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
49
55
'length_type' : 'main' ,
50
56
'length_min' : '' ,
51
57
'length_max' : '' ,
52
- 'detail' : search_modifiers .value
58
+ 'detail' : search_modifiers .value ,
59
+ 'v' : '' ,
60
+ 'f' : '' ,
61
+ 'g' : '' ,
62
+ 'randomize' : '0'
53
63
}
54
64
# Make the post request and return the result if is valid
55
- r = requests .post (HTMLRequests .SEARCH_URL , data = payload , headers = headers )
56
- if r is not None and r .status_code == 200 :
57
- return r .text
65
+ resp = requests .post (HTMLRequests .SEARCH_URL , params = params , headers = headers , data = payload )
66
+ if resp is not None and resp .status_code == 200 :
67
+ return resp .text
58
68
else :
59
69
return None
60
70
61
71
@staticmethod
62
- async def send_async_web_request (game_name : str , search_modifiers : SearchModifiers = SearchModifiers .NONE ):
72
+ async def send_async_web_request (game_name : str , search_modifiers : SearchModifiers = SearchModifiers .NONE , page : int = 1 ):
63
73
"""
64
74
Function that search the game using an async request
65
75
@param game_name: The original game name received as input
66
76
@param search_modifiers: The "Modifiers" list in "Search Options", allow to show/isolate/hide DLCs
77
+ @param page: The page to explore of the research, unknown if this is actually used
67
78
@return: The HTML code of the research if the request returned 200(OK), None otherwise
68
79
"""
69
80
ua = UserAgent ()
81
+ params = {
82
+ 'page' : str (page )
83
+ }
70
84
headers = {
71
85
'content-type' : 'application/x-www-form-urlencoded' ,
72
86
'accept' : '*/*' ,
73
- 'User-Agent' : ua .random
87
+ 'User-Agent' : ua .random ,
88
+ 'origin' : 'https://howlongtobeat.com' ,
89
+ 'referer' : 'https://howlongtobeat.com/'
74
90
}
75
91
payload = {
76
92
'queryString' : game_name ,
@@ -81,11 +97,15 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
81
97
'length_type' : 'main' ,
82
98
'length_min' : '' ,
83
99
'length_max' : '' ,
84
- 'detail' : search_modifiers .value
100
+ 'detail' : search_modifiers .value ,
101
+ 'v' : '' ,
102
+ 'f' : '' ,
103
+ 'g' : '' ,
104
+ 'randomize' : '0'
85
105
}
86
106
# Make the post request and return the result if is valid
87
107
async with aiohttp .ClientSession () as session :
88
- async with session .post (HTMLRequests .SEARCH_URL , data = payload , headers = headers ) as resp :
108
+ async with session .post (HTMLRequests .SEARCH_URL , params = params , headers = headers , data = payload ) as resp :
89
109
if resp is not None and str (resp .status ) == "200" :
90
110
return await resp .text ()
91
111
else :
@@ -118,14 +138,16 @@ def get_game_title(game_id: int):
118
138
"""
119
139
120
140
ua = UserAgent ()
141
+ params = {
142
+ 'id' : str (game_id )
143
+ }
121
144
headers = {
122
- 'User-Agent' : ua .random
145
+ 'User-Agent' : ua .random ,
146
+ 'referer' : 'https://howlongtobeat.com/'
123
147
}
124
148
125
- url_get = HTMLRequests .GAME_URL + str (game_id )
126
-
127
149
# Request and extract title
128
- contents = requests .get (url_get , headers = headers )
150
+ contents = requests .get (HTMLRequests . GAME_URL , params = params , headers = headers )
129
151
return HTMLRequests .__cut_game_title (contents .text )
130
152
131
153
@staticmethod
@@ -137,15 +159,17 @@ async def async_get_game_title(game_id: int):
137
159
"""
138
160
139
161
ua = UserAgent ()
162
+ params = {
163
+ 'id' : str (game_id )
164
+ }
140
165
headers = {
141
- 'User-Agent' : ua .random
166
+ 'User-Agent' : ua .random ,
167
+ 'referer' : 'https://howlongtobeat.com/'
142
168
}
143
169
144
- url_get = HTMLRequests .GAME_URL + str (game_id )
145
-
146
170
# Request and extract title
147
171
async with aiohttp .ClientSession () as session :
148
- async with session .post (url_get , headers = headers ) as resp :
172
+ async with session .post (HTMLRequests . GAME_URL , params = params , headers = headers ) as resp :
149
173
if resp is not None and str (resp .status ) == "200" :
150
174
text = await resp .text ()
151
175
return HTMLRequests .__cut_game_title (text )
0 commit comments