Python爬取4399好wan的小游戏!
此代码转载而来,作者也不会python爬虫,实在抱歉
代码转自:https://www.cnblogs.com/BigBallon/p/6215898.html
#coding=utf-8
#爬取4399所有好玩的游戏
import re
import os
import requests
# 基础url
host_url = \'http://www.4399.com\'
swfbase_url = \'http://sda.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 ("正在保存游戏:" , l[1] )
open( "./swf/"+ l[1] + ".swf", "wb" ).write( src )
版权声明:本文为N-S-P原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。