@@ -23,22 +23,28 @@ class SearchModifiers(Enum):
2323
2424class HTMLRequests :
2525 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="
2828
2929 @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 ):
3131 """
3232 Function that search the game using a normal request
3333 @param game_name: The original game name received as input
3434 @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
3536 @return: The HTML code of the research if the request returned 200(OK), None otherwise
3637 """
3738 ua = UserAgent ()
39+ params = {
40+ 'page' : str (page )
41+ }
3842 headers = {
3943 'content-type' : 'application/x-www-form-urlencoded' ,
4044 'accept' : '*/*' ,
41- 'User-Agent' : ua .random
45+ 'User-Agent' : ua .random ,
46+ 'origin' : 'https://howlongtobeat.com' ,
47+ 'referer' : 'https://howlongtobeat.com/'
4248 }
4349 payload = {
4450 'queryString' : game_name ,
@@ -49,28 +55,38 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
4955 'length_type' : 'main' ,
5056 'length_min' : '' ,
5157 'length_max' : '' ,
52- 'detail' : search_modifiers .value
58+ 'detail' : search_modifiers .value ,
59+ 'v' : '' ,
60+ 'f' : '' ,
61+ 'g' : '' ,
62+ 'randomize' : '0'
5363 }
5464 # 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
5868 else :
5969 return None
6070
6171 @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 ):
6373 """
6474 Function that search the game using an async request
6575 @param game_name: The original game name received as input
6676 @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
6778 @return: The HTML code of the research if the request returned 200(OK), None otherwise
6879 """
6980 ua = UserAgent ()
81+ params = {
82+ 'page' : str (page )
83+ }
7084 headers = {
7185 'content-type' : 'application/x-www-form-urlencoded' ,
7286 'accept' : '*/*' ,
73- 'User-Agent' : ua .random
87+ 'User-Agent' : ua .random ,
88+ 'origin' : 'https://howlongtobeat.com' ,
89+ 'referer' : 'https://howlongtobeat.com/'
7490 }
7591 payload = {
7692 'queryString' : game_name ,
@@ -81,11 +97,15 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
8197 'length_type' : 'main' ,
8298 'length_min' : '' ,
8399 'length_max' : '' ,
84- 'detail' : search_modifiers .value
100+ 'detail' : search_modifiers .value ,
101+ 'v' : '' ,
102+ 'f' : '' ,
103+ 'g' : '' ,
104+ 'randomize' : '0'
85105 }
86106 # Make the post request and return the result if is valid
87107 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 :
89109 if resp is not None and str (resp .status ) == "200" :
90110 return await resp .text ()
91111 else :
@@ -118,14 +138,16 @@ def get_game_title(game_id: int):
118138 """
119139
120140 ua = UserAgent ()
141+ params = {
142+ 'id' : str (game_id )
143+ }
121144 headers = {
122- 'User-Agent' : ua .random
145+ 'User-Agent' : ua .random ,
146+ 'referer' : 'https://howlongtobeat.com/'
123147 }
124148
125- url_get = HTMLRequests .GAME_URL + str (game_id )
126-
127149 # Request and extract title
128- contents = requests .get (url_get , headers = headers )
150+ contents = requests .get (HTMLRequests . GAME_URL , params = params , headers = headers )
129151 return HTMLRequests .__cut_game_title (contents .text )
130152
131153 @staticmethod
@@ -137,15 +159,17 @@ async def async_get_game_title(game_id: int):
137159 """
138160
139161 ua = UserAgent ()
162+ params = {
163+ 'id' : str (game_id )
164+ }
140165 headers = {
141- 'User-Agent' : ua .random
166+ 'User-Agent' : ua .random ,
167+ 'referer' : 'https://howlongtobeat.com/'
142168 }
143169
144- url_get = HTMLRequests .GAME_URL + str (game_id )
145-
146170 # Request and extract title
147171 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 :
149173 if resp is not None and str (resp .status ) == "200" :
150174 text = await resp .text ()
151175 return HTMLRequests .__cut_game_title (text )
0 commit comments