How can I get the average price from a list of scraped items' prices from ebay?
This is my code:
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import requests
from requests_html import HTMLSession
link = "https://www.ebay.co.uk/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=5035224123933&_sacat=0&LH_TitleDesc=0&_odkw=EAN5035224123933&_osacat=0"
req = Request(link, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
with requests.Session() as c:
soup = BeautifulSoup(webpage, 'html5lib')
lists = soup.find_all('li', class_="s-item s-item__pl-on-bottom s-item--watch-at-corner")
for list in(lists):
price=float(list.find('span', class_="s-item__price").text.replace('£',''))
avg = sum(price)/len(price)
I've tried:
avg = sum(price)/len(price)
But it gives an error:
TypeError: 'float' object is not iterable