Beautiful Soup Simple Python Error With Finding Elements Within Elements?
I've come across a BS4 error that gives no explanation, at least not one I understand, could someone help me know what it means? here is the code: soup = BeautifulSoup(browser.
Solution 1:
containerlv2
is a tag object, and it does not have 6 as key, therefore you got KeyError: 6
If you are trying to search for div
tag in the 7th tr
tag, the correct way should be:
containerlv2 = container.find_all('tr')
related_files = containerlv2[6].find('div')
First you use find_all
to get all tr
tags in container
and put them into a list containerlv2
, and then you search for div
in the 7th tag of containerlv2
Solution 2:
containerlv2 = container.find('tr')
this will return a tag object, and you index a tag object like this
containerlv2[6]
Post a Comment for "Beautiful Soup Simple Python Error With Finding Elements Within Elements?"