Adrian Ordona <adrian.ord...@gmail.com> writes:

> Hi,
>
> I’m learning how to code and interested in web scrapping to gather data.
> I’m running on Mac OS X 10.9.5 and python 3.7 terminal.
> I’m trying to capture the name of the brand and price but i keep getting an 
> error (see below).
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/anaconda3/lib/python3.7/site-packages/bs4/element.py", line 1884, in 
> __getattr__
>     "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()?
>
>
> Here’s what i got and thanks for the help
>
> import bs4
> from urllib.request import urlopen as uReq
> from bs4 import BeautifulSoup as soup
>
> my_url = 
> 'https://www.newegg.com/Desktop-Graphics-Cards/SubCategory/ID-48?Tid=7709'
>
> uClient = uReq(my_url)
> page_html = uClient.read()
> uClient.close()
> page_soup = soup(page_html, "html.parser")
> records = []
>
> containers = page_soup.findAll("div",{"class":"item-container"})
>
> for container in containers:
>       brand = container.find('div', attrs={'class':'item-branding'})
>       price = container.find('div', attrs={'class':'item-action'})
>       records.append((brand, price))
>
When I put this in a python file, and run it under python3.7, it works.
It seems you were running this line by line interactively, tight?

Could it be that you accidentally entered
brand = containers.find('div', attrs={'class':'item-branding'})
i.e containers rather than container, because that would generate the error 
that you copied.
-- 
Piet van Oostrum <pie...@vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to