-
Notifications
You must be signed in to change notification settings - Fork 0
/
gametimeinfo.py
50 lines (46 loc) · 1.24 KB
/
gametimeinfo.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
# -*- coding: utf-8 -*-
import urllib
import urllib.request
import re
pageurl = input('输入你的steam个人主页网址:')
url = pageurl + '/games/?tab=all'
data = urllib.request.urlopen(url).read() #读取网页
data = data.decode('utf-8')
#提取游戏名
pname = re.compile(r'\bname\"\:\"(.*?)\"',re.S)
gamename = re.findall(pname,data)
print (gamename)
#提取游戏时间
ptime = re.compile(r'\"hours\_forever\"\:\"(.*?)\"')
gametime = re.findall(ptime,data)
#print (gametime)
#将游戏名和时间依次按序合并
n=1
for i in gametime:
gamename.insert(n,i)
n += 2
#print(gamename)
#写入文档
file = open('gametimeinfo.txt','w+')
t=0
#加入| 作为分隔符
for i in gamename:
if t == 0:
file.write(i)
file.write('|')
t += 1
else:
value = re.compile(r'^[0-9]+\.?[0-9]?$')
result = value.match(i)
if result:
file.write(i)
file.write('\n')
t -= 1
else:
file.write('\n')
file.write(i)
file.write('|\n')
t -= 1
print (file) #输出一下组合的结果
file.close()
print('一切数据已放在目录下的gametimeinfo.txt文件内。')