Skip to content

Commit 1cbed6e

Browse files
committed
Updated.
1 parent 4ec0e3d commit 1cbed6e

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

html_parsing/get_price_game/from_gog.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,35 @@
44
__author__ = "ipetrash"
55

66

7-
import sys
87
import requests
98

109

11-
text = "titan quest"
12-
url = (
13-
"https://www.gog.com/games/ajax/filtered?language=en&mediaType=game&page=1&sort=bestselling"
14-
f"&system=windows_10,windows_7,windows_8,windows_vista,windows_xp&search={text}"
15-
)
10+
session = requests.Session()
11+
session.headers[
12+
"User-Agent"
13+
] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0"
1614

17-
rs = requests.get(url)
18-
print(rs)
1915

20-
data = rs.json()
21-
print(data)
16+
def get_games(name: str) -> list[tuple[str, int]]:
17+
url = f"https://www.gog.com/games/ajax/filtered?language=ru&mediaType=game&page=1&search={name}"
2218

23-
if not data["totalGamesFound"]:
24-
print("Not found game")
25-
sys.exit()
19+
rs = session.get(url)
20+
rs.raise_for_status()
2621

27-
for game in data["products"]:
28-
print(game["title"], game["price"]["amount"] + game["price"]["symbol"])
22+
data = rs.json()
23+
24+
return [
25+
(game["title"], game["price"]["amount"])
26+
for game in data["products"]
27+
]
28+
29+
30+
if __name__ == "__main__":
31+
print(get_games("titan quest"))
32+
# [('Titan Quest: Eternal Embers', '649'), ('Titan Quest Anniversary Edition', '649'), ('Titan Quest: Atlantis', '449'), ('Titan Quest: Ragnarök', '649')]
33+
34+
print(get_games("Titan Quest: Atlantis"))
35+
# [('Titan Quest: Atlantis', '449')]
36+
37+
print(get_games("dfsfsdfdsf"))
38+
# []

0 commit comments

Comments
 (0)