-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4399game.py
More file actions
36 lines (28 loc) · 980 Bytes
/
Copy path4399game.py
File metadata and controls
36 lines (28 loc) · 980 Bytes
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
#coding=utf-8
#爬取4399好玩的游戏
import re
import os
import requests
# 基础url
host_url = 'http://www.4399.com'
swfbase_url = 'http://szhong.4399.com/4399swf'
hw_url = 'http://www.4399.com/flash/gamehw.htm'
if not os.path.exists('./swf'):
os.mkdir(r'./swf')
# 需要的正则表达式
tmp_pat = re.compile(r'<ul class="tm_list">(.*?)</ul>',re.S)
game_pat = re.compile( r'<li><a href="(/flash.*?)"><img alt=.*?src=".*?"><b>(.*?)</b>.*?</li>', re.S )
swf_pat = re.compile(r'_strGamePath="(.*?swf)"',re.S)
game_html = requests.get(hw_url)
game_html.encoding = 'gb2312'
tt = tmp_pat.search(game_html.text,re.S).group(1)
game_list = game_pat.findall(tt)
for l in game_list:
# print l[0], l[1]
game_page = requests.get(host_url + l[0]).text
src_url = swf_pat.search(game_page)
if src_url == None:
continue;
src = requests.get( swfbase_url + src_url.group(1) ).content
print u"正在保存游戏:" , l[1]
open( "./swf/"+ l[1] + ".swf", "wb" ).write( src )