我几乎已经完成了一项我正在研究的软件应该有效,但没有。该软件旨在执行以下操作:
但是在运行下载的脚本的过程中发生了异常错误。
python netscript.py [URL FOR TARGET FILE] [ARGUMENTS FOR TARGET FILE|
错误:
File "temp_dl/431341022.py", line 146
^
IndentationError: expected an indented block
代码:
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)