@@ -23,6 +23,8 @@ class SearchModifiers(Enum):
2323
2424class HTMLRequests :
2525 BASE_URL = 'https://howlongtobeat.com/'
26+ ORIGIN_HEADER = 'https://howlongtobeat.com'
27+ REFERER_HEADER = BASE_URL
2628 SEARCH_URL = BASE_URL + "search_results"
2729 GAME_URL = BASE_URL + "game?id="
2830
@@ -43,8 +45,8 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
4345 'content-type' : 'application/x-www-form-urlencoded' ,
4446 'accept' : '*/*' ,
4547 'User-Agent' : ua .random ,
46- 'origin' : 'https://howlongtobeat.com' ,
47- 'referer' : 'https://howlongtobeat.com/'
48+ 'origin' : HTMLRequests . ORIGIN_HEADER ,
49+ 'referer' : HTMLRequests . REFERER_HEADER
4850 }
4951 payload = {
5052 'queryString' : game_name ,
@@ -63,7 +65,7 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
6365 }
6466 # Make the post request and return the result if is valid
6567 resp = requests .post (HTMLRequests .SEARCH_URL , params = params , headers = headers , data = payload )
66- if resp is not None and resp .status_code == 200 :
68+ if resp .status_code == 200 :
6769 return resp .text
6870 else :
6971 return None
@@ -85,8 +87,8 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
8587 'content-type' : 'application/x-www-form-urlencoded' ,
8688 'accept' : '*/*' ,
8789 'User-Agent' : ua .random ,
88- 'origin' : 'https://howlongtobeat.com' ,
89- 'referer' : 'https://howlongtobeat.com/'
90+ 'origin' : HTMLRequests . ORIGIN_HEADER ,
91+ 'referer' : HTMLRequests . REFERER_HEADER
9092 }
9193 payload = {
9294 'queryString' : game_name ,
@@ -124,7 +126,7 @@ def __cut_game_title(game_title: str):
124126 if game_title is None or len (game_title ) == 0 :
125127 return None
126128
127- title = re .search ("<title>([\w\W] *)<\/title>" , game_title )
129+ title = re .search ("<title>(. *)<\/title>" , game_title )
128130 # The position of start and end of this method may change if the website change
129131 cut_title = str (html .unescape (title .group (1 )[12 :- 17 ]))
130132 return cut_title
@@ -143,7 +145,7 @@ def get_game_title(game_id: int):
143145 }
144146 headers = {
145147 'User-Agent' : ua .random ,
146- 'referer' : 'https://howlongtobeat.com/'
148+ 'referer' : HTMLRequests . REFERER_HEADER
147149 }
148150
149151 # Request and extract title
@@ -164,7 +166,7 @@ async def async_get_game_title(game_id: int):
164166 }
165167 headers = {
166168 'User-Agent' : ua .random ,
167- 'referer' : 'https://howlongtobeat.com/'
169+ 'referer' : HTMLRequests . REFERER_HEADER
168170 }
169171
170172 # Request and extract title
0 commit comments