Python Forum
Getting 'list index out of range' while fetching product details using BeautifulSoup?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting 'list index out of range' while fetching product details using BeautifulSoup?
#9
The whole thing is messy as pointed out bye @buran.
It's not code that we can run,missing imports and call to function.
attrs={"class": "buy"}
Do you find a class='buy' on that site?

Just to show a quick test,with code that can be run(no missing parts).
Take out name of featured product,class_='price' will take out price.
import requests
from bs4 import BeautifulSoup

url = 'http://www.infantree.net/shop/'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
#print(soup)
featured = soup.find('section', class_="featured span")
li = featured.find_all('li')
for item in li:
    print(item.find('div', class_='name').text.strip())
Output:
THE FIRST YEARS Bottle Warmer and Cooler THE FIRST YEARS Steam Sterilizer AMEDA Store'N Pour Breast Milk Storage Bags AMEDA Lactaline Personal Breastpump LASCAL Kiddy Guard Accent - Black
Do small test like this first to make sure that all work.
If get error in this short code,it's easy to see what's wrong.
Then can structure in functions(not to much code in one function).
Reply


Messages In This Thread
RE: Getting 'list index out of range' while fetching product details using BeautifulSoup? - by snippsat - Jun-06-2018, 12:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fetching Images from DB in Django Dexty 2 1,719 Mar-15-2024, 08:43 AM
Last Post: firn100
  All product links to products on a website MarionStorm 0 1,087 Jun-02-2022, 11:17 PM
Last Post: MarionStorm
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 3,517 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  Python BeautifulSoup IndexError: list index out of range rhat398 1 6,242 May-28-2021, 09:09 PM
Last Post: Daring_T
  fetching, parsing data from Wikipedia apollo 2 3,549 May-06-2021, 08:08 PM
Last Post: snippsat
  How to make data coming from a database clickable giving more details newbie1 8 3,762 May-29-2020, 11:19 PM
Last Post: newbie1
  IndexError: tuple index out of range ? JohnnyCoffee 4 3,404 Jan-22-2020, 06:54 AM
Last Post: JohnnyCoffee
  Fetching and Parsing XML Data FalseFact 3 3,256 Apr-01-2019, 10:21 AM
Last Post: Larz60+
  My Django 2.0.6 logging is not working while product merging PrateekG 0 2,162 Jul-26-2018, 02:24 PM
Last Post: PrateekG
  from List to BeautifulSoup , Homework RPC 6 7,035 Jul-03-2018, 12:17 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020