python - 从 bs4 导入 BeautifulSoup ModuleNotFoundError:没有名为“bs4”的模块
问题描述
我正在做一个网络抓取项目,但我不明白为什么我的程序拒绝import bs4
。
我已经解决了几个小时的问题,尝试设置路径,确保安装了轮子,是的,我使用pip3
了,我的python
和pip
都更新了,大写似乎与其他人的进口相匹配......有人可以帮忙吗?代码摘录如下:
from bs4 import BeautifulSoup
import requests
horse_List = []
horse_List_Soup = []
BASE_URL = 'https://www.horseracingnation.com/horse/' #create a base url to build from
HEADERS = {'User-Agent': 'Mozilla/5.0'} #user-agent added so that webpage doesn't reject request
def get_Horse_Soup():
for num in range(len(horse_List)):
incorrect = True
while(incorrect):
response = requests.get(BASE_URL + horse_List[num]) #GET request method with specified url
if not response.status_code == 200: #catches errors if request is not ok (code 200)
if response.status.code == 404:
raise Exception("Horse not found. Try searching another name.")
name = input("Input a new name for rachorse #" + num + ": ")
name.replace(" ", "_")
horse_List[num] = name
else:
raise Exception("Web request failed. Status Code: " + str(response.status_code))
else:
incorrect = False
horse_List_Soup[num] = BeautifulSoup(response.content, "lxml")
def main():
get_Horse_Soup()
main()
追溯这里:
回溯(最后一次调用):文件“C:\Users\Kisra\Desktop\DataViz_Project\KO_HorseSoup.py”,第 1 行,从 bs4 导入 BeautifulSoup ModuleNotFoundError:没有名为“bs4”的模块
解决方案
确保您运行代码的 python 内核与您 pip 安装的 bs4 相同。如果您有 32 位 python 内核 pip 包,则不适用于您的 64 内核,反之亦然
推荐阅读
- c# - 如何通过 C#(.net) 连接 aws rds(mysql)
- c# - 如何检查正在播放的动画
- typescript - 找不到 Vue 组件
- android - 改造错误:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法
- html - 是什么导致屏幕侧面出现这种间隙?引导网格系统
- java - 从一系列用户输入中拆分字符串
- logging - Google Apps Script V8 vs Rhino 的“日志”非常慢?
- r - R Script- Cumsum() reseting when there is a new customer id
- asp.net-mvc - Visual Studio:系统找不到指定的路径
- r - 如何应用函数来改变特定的列组合?(purrr:: 使用首选)