VS Code中的代码运行器无法将漂亮的汤识别为模块

时间:2019-05-15 18:35:48

标签: python beautifulsoup vscode-code-runner

我正在做一个基本的文档摘要,我正在使用BeautifulSoup在VS Code中解析文档。

当我在终端中运行代码时,它没有错误运行。但是,当我使用Code Runner获得输出时,它返回错误“ ImportError:No名为bs4的模块”。 我认为bs4可能有问题,因此我尝试了多种导入格式:

from bs4 import BeautifulSoup4 as bs
import BeautifulSoup as bs
import BeautifulSoup4 as bs

我通过pip卸载了bs4并将其重新安装到Python 2.7和Python3.7。

这是我认为应该工作的代码的上下文。

import urllib.request
import re
scraped_data=urllib.request.urlopen('http://test.com/path.pdf')
article = scraped_data.read()

parsed_Article=bs.BeautifulSoup(article, 'lxml')

它应该将bs4识别为BeautifulSoup4并按其运行方式以解析网页文档。取而代之的是,它给出的错误是不存在名为bs4的模块。所有代码的最终结果将是url文档的7句摘要。我相信这是一个Code Runner问题,因为它在Terminal中运行正常。由于我需要print(summary)作为输出,因此我使用了Code Runner。也许我应该使用其他程序来运行代码并获得7句摘要。

0 个答案:

没有答案