Beautiful soup returns empty while using class name to filter datas

106 views Asked by At

Im trying to retrieve the product names, weight and price in a list from the following site.

https://www.licious.in/seafood

my code to find the products list :

  import requests
  from bs4 import BeautifulSoup

  URL = 'https://www.licious.in/seafood'
  r = requests.get(URL)
  soup = BeautifulSoup(r.content, 'lxml')

  productlist = soup.find_all('div', class_="card")

  productlinks = []

  for card in productlist:
        for link in card.find_all('a', href=True):
  print(link['href'])

Can I use css selector for the product prices and product weight ?

1

There are 1 answers

5
Prophet On

I see several issues here:

  1. Missing indentation
  2. Product images you are trying to get with soup.find_all("div", {"class": "product_image"}) are img elements, not div
  3. img1 object received by item.find("img") is not printable.
    This should work better:
import requests,
from bs4 import BeautifulSoup

URL = 'https://www.licious.in/seafood'
r = requests.get(URL)
soup = BeautifulSoup(r.text)
product_list = soup.find_all("div", {"class": "item-details"})

for item in product_list:

    product_names = item.find_all("div", {"class":  "item-title"})
# I see no point where detail_link_h2, detail_link_h3 and detail_link_h4 are defined so this will not work
#print(detail_link_h2 + ", " + detail_link_h3 + ", " + detail_link_h4)

product_images = soup.find_all("img", {"class": "product_image"})

for image in product_images:

    img1 = image.find("img")
#    print(img1)