从bs4导入BeautifulSoup ModuleNotFoundError:没有名为“ bs4”的模块

时间:2020-05-03 05:23:34

标签: python beautifulsoup

我正在做一个使用Web抓取的项目,但我不明白为什么我的程序拒绝import bs4

我几个小时都无法解决问题,尝试设置路径,确保安装了车轮,是的,我使用了pip3,我的pythonpip都已更新,大小写似乎匹配其他国家的进口商品……有人可以帮忙吗?代码摘录如下:

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”的模块

1 个答案:

答案 0 :(得分:-1)

确保运行代码的python内核与pip安装的bs4相同。如果您拥有32位python内核pip软件包,则该软件包不适用于您的64内核,反之亦然