0

html变量是一个包含整个网页源代码的字符串,例如

html = "<!doctype html>\n<html><head><title>My title</title></head>LOTS OF CHARS HERE</html>"

如果可能的话,我想以print人类可读的格式制作这个网页lynx。我尝试了各种各样的事情

print(subprocess.run(['echo', html, '|', 'lynx', '-stdin', '-dump'], capture_output=True, text=True).stdout)

或者

p1 = subprocess.Popen(["echo", html], stdout=subprocess.PIPE)
print(subprocess.run(['lynx', '-stdin', '-dump'], stdin=p1.stdout, capture_output=True, text=True).stdout)

但它失败并出现以下错误

OSError:[Errno 7] 参数列表太长:'echo'

知道如何使它工作吗?

4

1 回答 1

2

不需要 for echohtml用作inputfor lynx

print(subprocess.run(['lynx', '-stdin', '-dump'], input=html, capture_output=True, text=True).stdout)
于 2021-09-07T16:30:39.007 回答