python - VS Code 中的代码运行程序无法将 Beautiful Soup 识别为模块
问题描述
我正在做一个基本的文档摘要,我正在使用 BeautifulSoup 来解析 VS Code 中的文档。
当我在终端中运行我的代码时,它运行时没有错误。但是,当我使用 Code Runner 获取输出时,它返回错误“ImportError: No module named 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 问题,因为它在终端中运行良好。因为我需要 print(summary) 作为输出,所以我使用的是 Code Runner。也许我应该使用不同的程序来运行代码并获取 7 句摘要。
解决方案
推荐阅读
- python - Django - 读取数据库记录太慢
- c# - 我的 HTTPClient Post Message 的正文不适用于我的服务器
- post - TypeError:无法在 Swagger 中获取
- mongodb - 找不到文件
- continuous-integration - 即使一个失败,Gitlab 也会执行下一阶段(有依赖关系)
- typescript - 使用 map 将数组合并到对象数组中
- python-3.x - ImportError:无法从“requests_html”导入名称“HTMLSession”
- swift4 - 是否有一种解决方法可以将方法“呈现”在 UIimageView 类中?
- vba - VBA 新手,我需要根据单元格的更新更改单元格颜色
- c# - 使用下拉框中的值更新 DataGridView 中选定行的单元格值