在php中显示beautifulsoup结果时出现问题

2024-04-25 20:00:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习如何运行python脚本并用php打印结果。我想知道为什么我要在我的php文件中写这个:

$output = shell_exec('python newfile.py');
echo "<pre>$output</pre>";

在我的python文件中:

print("Hello");

一切正常,当我运行php文件时,会显示单词“Hello”,但是如果我在python文件中编写以下内容,则不会显示任何内容:

soup = BeautifulSoup(html, features='lxml')

  whatIneed= soup.findAll(True, {"id": ["errors"]})

  list = []
  for x in whatIneed:
      list.append(str(x))

  print(str(list))

PS:我需要整个字符串,所有的html标签,这就是为什么我要使用beautifulsoup。你知道吗


Tags: 文件脚本hellooutputhtmlshellprelist