Scraping deliveroo price

Viewed 80

I should do some web scraping of multiple deliveroo sites, the information I need to extract is the header of the various products and the price. I have tried using the BeautifulSoup library, but the information I need to extract is quite nested. I set up the code like this:

import pandas as pd
import requests
#the website URL
url_link = "https://deliveroo.it/en/menu/jesolo/jesolo/burger-king-jesolo"
result = requests.get(url_link)
print(result)

I can tell from here that I can do scraping because the result is: <Response [200]>

from bs4 import BeautifulSoup
doc = BeautifulSoup(result, "html.parser")
print(doc.prettify())

Deliveroo html site

The end result should be a database with title and price information, for example:

  • Plant based nuggets burger - menu -> 8.20

  • Crazy cheese bbq - menu -> 11.10

  • etc.

From here I can't go any further, I hope I was clear with respect to what I need to do, in case anyone can solve the problem I would be very grateful

EDIT 1

import pandas as pd
from bs4 import BeautifulSoup
import requests

siti=["https://deliveroo.it/it/menu/roma/piazza-venezia/burger-king-via
nazionale","https://deliveroo.it/en/menu/jesolo/jesolo/burger-king
jesolo",'https://deliveroo.it/it/menu/roma/via-tiburtina/burger-king
via-tiburtina']

for url in siti:
  result = requests.get(url)
  doc = BeautifulSoup(result.content, "html.parser")
  menus = doc.findAll("div", class_="UIMenuItemCard-3b733b66e7f3b27d")
  db_name=[]
  db_price=[]
  for menu in menus:
    name = menu.find("p", class_="ccl-a396bc55704a9c8a")
    price = menu.find("span", class_="ccl-08c109442f3e666d")
    #print(name.text + " > " + price.text)

    db_name.append(name.text)
    db_price.append(price.text)

df_name = pd.DataFrame (db_name, columns = ['name'])
df_price = pd.DataFrame (db_price, columns = ['price'])
df=df_name.join(df_price)

I went ahead with the work and now I can't scrap multiple sites, the moment I launch this code it scrapes the last URL in the list. I should be scraping all the different sites at the same time and putting them into a dataframe. So in output I would need a table always with two columns (name and price) of all URLs together, if possible every time it changes URL insert a space. If anyone could help me I would be grateful

1 Answers

First what you have to do is find the parent element (wrapped element) and then iterate over it looking for the elements you want.
You need to do something like this:

from bs4 import BeautifulSoup
import requests

url_link = "https://deliveroo.it/en/menu/jesolo/jesolo/burger-king-jesolo"
result = requests.get(url_link)
doc = BeautifulSoup(result.content, "html.parser")

menus = doc.findAll("div", class_="UIMenuItemCard-3b733b66e7f3b27d")
for menu in menus:
    name = menu.find("p", class_="ccl-a396bc55704a9c8a")
    price = menu.find("span", class_="ccl-08c109442f3e666d")
    print(name.text + " > " + price.text)

OUTPUT:

Plant based nuggets burger - menù > €8.20
Crazy cheese bbq - menù > €11.10
Crazy cheese chicken bbq - menù > €11.10
Related