继承我的代码.
import os, sys if len(sys.argv) != 2: sys.exit(1) h = os.popen("wget -r %s") % sys.argv[1] fil = open("links.txt","w") dir = os.listdir("%s") % sys.argv[1] for file in dir: print file.replace("@","?") fil.write("%s/"+file.replace("@","?")) % sys.argv[1] fil.write("\n") h.close()
运行它,就像这个python project.py http://google.com
给我错误代码.
1.py:5 RuntimeWarning: tp_compare didnt return -1 or -2 for exception h = os.popen("wget -r %s") % sys.argv[1] Traceback (most recent call last): File "1.py" line 5, inh = os.popen("wget -r %s") % sys.argv[1] TypeError: unsupported operand type for %: 'file' and 'str'
什么是我出错了.(还在学习python)任何解决方案/提示?
我不解释代码,我想你明白我想做什么
h = os.popen("wget -r%s"%sys.argv [1])
使用子进程模块,os.popen已过时
python有urllib,你可以考虑使用它来拥有纯python代码
有pycurl