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 )



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM