python下载数据

亲爱的BSSN给了一个flash游戏的数据库,还给了一个通过wget下载其中flash游戏数据的教程。测试中发现那个教程中wget方式下载数据经常下载到一半碰到出错或者什么原因给自动退出了。

趁这两天换工作有点时间,操刀python写了一段小脚本:

# -*- coding:utf-8 -*-
import os.path
import urllib2
 
def header(url):
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6',
        'Referer':'http://www.xxx.net/'
    }
 
    req = urllib2.Request(
        url = url,
        headers = headers
    )
    result = urllib2.urlopen(req).read()
    return result
 
f = open('flash.txt', 'r')
for line in open('flash.txt', 'rb'):
    if not os.path.isfile(line.rstrip()):
        _file = line.rsplit('/',1)[1]
        try:
            File = open('files/flash/%s'%_file.rstrip(), "wb" )
            File.write(header("http://www.xxx.net/games/files/%s"%_file.rstrip()))
            File.close()
        except Exception, what:
            print what
        print _file

下载完共6G多的数据,周五再调试一下准备弄一个简单站点把这些数据放上去看看效果了。

Via:Chairo@2012年02月16日-EOF-

已有 3 条评论 »

  1. duke duke

    没关系,我知道咋弄了,太简单了。呵呵

  2. duke duke

    求flash.txt文件

    1. 这个比较抱歉,是朋友提供给我的,不是很方便公开。

添加新评论 »

captcha 请输入验证码