用wget命令下载文件总是失败。用python脚本模拟浏览器下载,代码如下:


#!/bin/python
# -*- coding: utf-8 -*-
__author__ = 'wulong'

import sys
from urllib import FancyURLopener

class MyOpener(FancyURLopener):
    def downPro(self):
        version = '''Mozilla/5.0 (X11; U; Linux i686 (x86_64); zh-CN; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2'''
        print version
        myopener=MyOpener()
        url = '''http://163.54114.com/upimg/allimg/120918/5-12091Q64133.jpg'''  #自己指定文件地址
        page=myopener.open(url)
        saveFile = file('download.jpg','wb+')
        try:
            while True:
                arr = page.read()
                if len(arr) == 0:
                    break
                saveFile.write(arr)
                print arr
        finally:
            page.close()
            saveFile.close()


p=MyOpener()
p.downPro()



Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐