使用Python无法在命令行中执行文件

时间:2018-02-18 05:56:42

标签: python data-analysis

我是python的初学者,我有一个包含URL列表的txt文件,当我想扫描txt文件时,我在最后一个看到KeyboardInterrupt的错误。这是我的代码
    如果名称 ==“主要”:

# Directory that contains panafapi.py
SCRIPT_DIRECTORY = "/Users/kiya/Downloads/panpython/bin"

RES_DIRECTORY = "/Users/kiya/Desktop/result/"
TODAY = datetime.date.today().strftime("%Y%m%d")

CHECK_DATE, NOW_DATE = "2018-01-01", "2018-01-31"    
try:
    url_file = sys.argv[1]
except Exception:
    print("Usage: python3 {} [url file]".format(sys.argv[0]))
    sys.exit()

url_file = str(url_file)
df=open(url_file,"r",encoding="utf-8", errors='replace')
data=df.readlines();df.close()
urlPattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')

url_list = []
for url in data:
    dt = url.strip()
    dt = re.findall(urlPattern,dt)# get URLs
    if dt:
        url_list.append(dt[0])
print("Read {} Url(s)".format(len(url_list)))
group_i = 0

1 个答案:

答案 0 :(得分:0)

我认为问题在于您将输出重定向到不存在的路径

/Users/kiya/Desktop/result/result767_http://blogimg.goo.ne.jp/.json

尝试像

这样的简单文件名
/Users/kiya/Desktop/result/result767_blogimg.goo.ne.jp.json