-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgameListCreator.py
58 lines (46 loc) · 1.51 KB
/
gameListCreator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from bs4 import BeautifulSoup as BS
import requests
def getSoup(url):
games = []
r = requests.get(url)
content = r.content
soup = BS(content, "html.parser")
games = getGameRow(soup)
return games
def getGameRow(soup):
games = []
gameRows = soup.find_all('div', {'class': 'game-row'})
# print("Getting game rows")
for gameRow in gameRows:
gameInfo = getGameInfo(gameRow)
if gameInfo is not None:
# print("Appending game info")
games.append(gameInfo)
return games
def getGameInfo(game):
gameName = game.find('div', {'class': 'game-name'})
href = gameName.find('a')
if href is None:
return None
# print("Getting game info")
gameUrl = "https://opencritic.com"+gameName.find('a')['href']+"/reviews"
gameInfo = {'Name': gameName.text,
'URL': gameUrl
}
# print(gameInfo)
return gameInfo
def main(url):
'''a function that returns a list of games with their name and url
parameters:
url: the url of the page from opencritic.com of the form
'https://opencritic.com/browse/all/all-time/num-reviews'
returns: a list of games each element of the list is a dictionary
with the keys 'Name' and 'URL'
'''
games = []
games = getSoup(url)
print("Returning games")
return games
if __name__ == "__main__":
url = "https://opencritic.com/browse/all/all-time/num-reviews"
soup = getSoup(url)