简体   繁体   中英

Beautiful Soup WebScraping Error - ResultSet object has no attribute '%s'

Hey there,

I've seen questions very similar this, however they are usually dealing with tables.

I am simply trying to scrape information off of the Harry Potter Wiki page, however when simply referencing/attempting to find tags in the html code, it pulls an error saying ResultSet object has no attribute '%s' . Here is my code (super simple):

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

my_url = "http://harrypotter.wikia.com/wiki/Harry_Potter"

uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()

page_soup = soup(page_html, "html.parser")

containers = page_soup.findAll("aside",{"class":"portable-infobox pi-background pi-theme-mom pi-layout-default"})

for container in containers:
    name_container = containers.find("h2", {"class":"pi-item pi-item-spacing pi-title"})

This then results in an error stating:

"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?

Which is odd, because I'm already using the find() function.

Even when I try to directly reference the specific tags through containers (see below), it still gives me the same error... And I'm not even using find() or findAll() this time!

for container in containers:
    name_container = containers.section.h2

Once again, this is not dealing with any form of table (that I can see), so I am really quite stumped as to why this error is being created. In fact, whenever I try to reference anything from containers , it gives me the same error.

Any help or advice would be appreciated, thanks.

User Stack found a typo in my code, should have been referencing container instead of containers, like this:

name_container = container.find("h2", {"class":"pi-item pi-item-spacing pi-title"})

Cheers, Stack .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM