-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.py
56 lines (36 loc) · 1.07 KB
/
function.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
from bs4 import BeautifulSoup
from urllib.request import urlopen, Request
import re
def steamContent(type):
#specials
specialUrl = 'http://store.steampowered.com/search/?specials=1&os=win.html'
#topsellers
topSellUrl = 'http://store.steampowered.com/search/?filter=topsellers&os=win.html'
#upcoming
upcomingUrl = 'http://store.steampowered.com/search/?filter=comingsoon&os=win.html'
if type == "Top Sellers":
url = topSellUrl
elif type == "Specials":
url = specialUrl
else:
url = upcomingUrl
#create request
request = Request(url)
#create a response to request content
response = urlopen(request)
#store content
steamHtml = response.read()
#closing request
response.close()
#creating a soup
soup = BeautifulSoup(steamHtml, "html.parser")
#make an array
name_array = []
for links in soup.find_all(href = re.compile("app")):
#creating array with regex to parse link
names = re.findall(r'[A-Z][A-Za-z]*', links.get("href"))
#append to an array
name_array.append(' '.join(names))
# #joining array
# print(' '.join(names))
return name_array