Я работаю над курсом Python Cra sh и попытался поэкспериментировать с BeautifulSoup. Я попробовал некоторые вещи и не смог найти решение, поэтому я спрашиваю здесь, что делать.
Итак, как мне избавиться от первого вывода, это не название бургера? И как мне избавиться от \ n и.?
Вот код:
from bs4 import BeautifulSoup as bs
import requests
source = requests.get('https://www.mcdonalds.com/us/en-us/full-menu/burgers.html').text
soup = bs(source, 'html.parser')
sandwiches_ordered = []
finished_sandwiches =[]
for menu in soup.find_all('div', id='maincatcontent'):
for burger in soup.find_all('div', class_='categories-item-details'):
sandwiches_ordered.append(burger.text)
print("We are making all the sandwiches!\n")
while sandwiches_ordered:
sandwich = sandwiches_ordered.pop()
finished_sandwiches.append(sandwich)
for sandwich in finished_sandwiches:
print(f"Here is your {sandwich}.")
И мой вывод:
We are making all the sandwiches!
Here is your
#{itemName}
#{nutrientValue}
.
Here is your
Hamburger
.
Here is your
Double Cheeseburger
.
Here is your
Cheeseburger
.
Here is your
Quarter Pounder®* with Cheese Bacon
.
Here is your
McDouble®
.
Here is your
Quarter Pounder®* with Cheese Deluxe
.
Here is your
Double Quarter Pounder®* with Cheese
.
Here is your
Quarter Pounder®* with Cheese
.
Here is your
Little Mac™
.
Here is your
Double Big Mac®
.
Here is your
Big Mac®
.