IndentationError:应为缩进块(奇怪)

2024-10-01 05:05:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我几乎完成了我正在开发的一个软件,该软件本应有效,但却没有成功。该软件旨在实现以下功能:

  1. 从internet下载python脚本。在
  2. 使用为下载的 文件

但是在运行下载的脚本的过程中发生了一个异常错误。在

    python netscript.py [URL FOR TARGET FILE]  [ARGUMENTS FOR TARGET FILE|

错误:

^{pr2}$

代码:

    from bs4 import BeautifulSoup
    from subprocess import call
    from sys import argv
    import urllib2
    import random
    import os


    script, url, ns_dledscript_arg =  argv
    def ns_runscript(ns_randfn, ns_dledscript_arg):
        print "Running downloaded content..."
        os.system("python temp_dl/%s.py %s" % (ns_randfn, ns_dledscript_arg))

    def ns_getcontent(url, ns_dledscript_arg):
        print "Getting content..."
        ns_openurl = urllib2.urlopen(url).read()
        print "Filtering content..."
        #ns_filtered_data = re.sub( r'<[^>]*>', ' ', ns_openurl).strip()
        ns_filtered_data = BeautifulSoup(ns_openurl, "html.parser")
        ns_randfn = random.randrange(100000000, 999999999)
        file = open("temp_dl/%s.py" % (ns_randfn), "w") #Create writable file with random name.
        file.write("""%s""" % (ns_filtered_data)) #writes pretty code into the file with the random name.
        ns_question_viewdata = raw_input("Do you want to print data on console? 'y' or 'n': ")
        ns_runscript(ns_randfn, ns_dledscript_arg)
        if ns_question_viewdata == 'y':
            print ns_filtered_data
        elif ns_question_viewdata == 'n':
            exit()
        else:
            exit()

    ns_getcontent(url, ns_dledscript_arg)

Tags: frompyimporturldataargrandomcontent