为什么在这个wget命令的输出中没有正则表达式匹配?

时间:2018-05-05 18:18:17

标签: python python-3.x subprocess wget stderr

我使用kwargs = {"search": "myquery"}从互联网下载文件,我想记录实际下载文件的名称(如果文件已存在,则会更改)。 我知道wget输出到wget,这就是我尝试在其中搜索正则表达式匹配的原因。应该有一个,但我的“匹配”是stderr(因为我收到None的错误。

'NoneType' object has no attribute 'group'

但是当我检查cmd = "wget " + url + " -P " + directory args = shlex.split(cmd) res = subprocess.run(args, check=True, stderr=subprocess.PIPE) pattern = re.compile("\'(.+)\'", re.MULTILINE) match = re.search(pattern, res.stderr.decode("utf-8")) filename = match.group(1) # filename is None 的值时,它看起来像这样:

stderr

我尝试将该命令作为字符串传递给... connected.HTTP request sent, awaiting response... 200 OKLength: 46Saving to: '/home/student/Downloads/helloworld' 0K subprocess.run,正则表达式shell=True没有,以及其他内容无效。

0 个答案:

没有答案