osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WebScrapping


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))