66import re
77import html
88from enum import Enum
9+ from fake_useragent import UserAgent
910
1011
1112# ---------------------------------------------------------------------
@@ -33,9 +34,11 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
3334 @param search_modifiers: The "Modifiers" list in "Search Options", allow to show/isolate/hide DLCs
3435 @return: The HTML code of the research if the request returned 200(OK), None otherwise
3536 """
37+ ua = UserAgent ()
3638 headers = {
3739 'content-type' : 'application/x-www-form-urlencoded' ,
38- 'accept' : '*/*'
40+ 'accept' : '*/*' ,
41+ 'User-Agent' : ua .random
3942 }
4043 payload = {
4144 'queryString' : game_name ,
@@ -63,9 +66,11 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
6366 @param search_modifiers: The "Modifiers" list in "Search Options", allow to show/isolate/hide DLCs
6467 @return: The HTML code of the research if the request returned 200(OK), None otherwise
6568 """
69+ ua = UserAgent ()
6670 headers = {
6771 'content-type' : 'application/x-www-form-urlencoded' ,
68- 'accept' : '*/*'
72+ 'accept' : '*/*' ,
73+ 'User-Agent' : ua .random
6974 }
7075 payload = {
7176 'queryString' : game_name ,
@@ -112,10 +117,15 @@ def get_game_title(game_id: int):
112117 @return: The game title from the given id
113118 """
114119
120+ ua = UserAgent ()
121+ headers = {
122+ 'User-Agent' : ua .random
123+ }
124+
115125 url_get = HTMLRequests .GAME_URL + str (game_id )
116126
117127 # Request and extract title
118- contents = requests .get (url_get )
128+ contents = requests .get (url_get , headers = headers )
119129 return HTMLRequests .__cut_game_title (contents .text )
120130
121131 @staticmethod
@@ -126,11 +136,16 @@ async def async_get_game_title(game_id: int):
126136 @return: The game title from the given id
127137 """
128138
139+ ua = UserAgent ()
140+ headers = {
141+ 'User-Agent' : ua .random
142+ }
143+
129144 url_get = HTMLRequests .GAME_URL + str (game_id )
130145
131146 # Request and extract title
132147 async with aiohttp .ClientSession () as session :
133- async with session .post (url_get ) as resp :
148+ async with session .post (url_get , headers = headers ) as resp :
134149 if resp is not None and str (resp .status ) == "200" :
135150 text = await resp .text ()
136151 return HTMLRequests .__cut_game_title (text )
0 commit comments