在python中使用wget(错误代码帮帮我)

0 python

继承我的代码.

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()
Run Code Online (Sandbox Code Playgroud)

运行它,就像这个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, in <module>
h = os.popen("wget -r %s") % sys.argv[1]
TypeError: unsupported operand type<s> for %: 'file' and 'str'
Run Code Online (Sandbox Code Playgroud)

什么是我出错了.(还在学习python)任何解决方案/提示?

我不解释代码,我想你明白我想做什么

Ano*_*ous 9

  1. h = os.popen("wget -r%s"%sys.argv [1])

  2. 使用子进程模块,os.popen已过时

  3. python有urllib,你可以考虑使用它来拥有纯python代码

  4. 有pycurl