Python Forum
Python BeautifulSoup IndexError: list index out of range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python BeautifulSoup IndexError: list index out of range
#2
There are several ways to fix this, here's a couple of ways I thought of:

Here's a oneliner for line 66
'price': None if item < titles else prices[item]
if you want a function:

def get(list, index, default=None):
	try:
		return list[index]
	except IndexError:
		return default
Reply


Messages In This Thread
RE: Python BeautifulSoup IndexError: list index out of range - by Daring_T - May-28-2021, 09:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange ModuleNotFound Error on BeautifulSoup for Python 3.11 Gaberson19 1 1,002 Jul-13-2023, 10:38 AM
Last Post: Gaurav_Kumar
  Python BeautifulSoup gives unusable text? dggo666 0 1,437 Oct-29-2021, 05:12 AM
Last Post: dggo666
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 3,518 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  Python 3.9 : BeautifulSoup: 'NoneType' object has no attribute 'text' fudgemasterultra 1 8,931 Mar-03-2021, 09:40 AM
Last Post: Larz60+
  Beautifulsoup doesn't scrape page (python 2.7) Hikki 0 1,994 Aug-01-2020, 05:54 PM
Last Post: Hikki
  Python beautifulsoup pagination error The61 5 3,479 Apr-09-2020, 09:17 PM
Last Post: Larz60+
  IndexError: tuple index out of range ? JohnnyCoffee 4 3,410 Jan-22-2020, 06:54 AM
Last Post: JohnnyCoffee
  from List to BeautifulSoup , Homework RPC 6 7,035 Jul-03-2018, 12:17 AM
Last Post: snippsat
  Getting 'list index out of range' while fetching product details using BeautifulSoup? PrateekG 8 8,168 Jun-06-2018, 12:15 PM
Last Post: snippsat
  How to clean html content using BeautifulSoup in Python 3.6? PrateekG 5 10,371 Apr-27-2018, 01:14 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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