Я пытаюсь запустить небольшой веб-скребок, но получаю ошибку:
Файл "scrape.py", строка 1, в
из bs4 импортировать BeautifulSoup
ModuleNotFoundError: нет модуля с именем 'bs4'
Я сделал 0 изменений в коде, и вчера он работал нормально, но внезапно это происходит. Я удалил pip & sudo pip как bs4 и beautifulsoup, так и переустановил их, но произошло то же самое.
from bs4 import BeautifulSoup as soup
import csv
import requests
from urllib.request import urlopen
my_url = 'https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38?Tpk=graphics%20card'
#Opening up connection & grabbing the page
urlClient = urlopen(my_url)
page_html = urlClient.read()
#Close the client
urlClient.close()
#HTML Parsing
page_soup = soup(page_html, 'html.parser')
#Cleans Up the HTML
#print(page_soup.prettify())
#Grabs each product
containers = page_soup.findAll('div', {'class':'item-container'})
#Fix using https://beautifier.io/ to see in a new tab
#Contains 1 graphic card
container = containers[0]
filename = 'NewEggScrape.csv'
f = open(filename, 'w')
headers = 'Brand Name, Product Name, Shipping Price, Price \n'
f.write(headers)
for container in containers:
divWithInfo = container.findAll('div',{'class':'item-info'})
brand = divWithInfo[0].div.a.img['title']
#print(brand)
title_container = container.findAll('a', {'class':'item-title'})
product_name = title_container[0].text
#print(product_name)
shipping_container = container.findAll('li', {'class':'price-ship'})
shipping = shipping_container[0].text.strip()
#print(shipping)
try:
price_container = container.findAll('li', {'class':'price-current'})
price = price_container[0].text.strip()
str(price)
price = price.replace('|', '')
price = price.replace('–', '')
price = price.rstrip('\n')
price.strip()
print(price)
except:
pass
f.write(brand + ',' + product_name.replace(',', '') + ',' + shipping + ',' + price + '\n')
f.close()
Это сработало вчера, но я не могу понять, почему эта ошибка продолжает появляться. Могу ли я получить помощь, пожалуйста?