How to get name and price of goods properly ?

28 views
Skip to first unread message

fsn7...@gmail.com

unread,
Jul 4, 2016, 10:39:11 PM7/4/16
to beautifulsoup
I'm newbie to bs4, I'm trying to get names and prices of laptops from a site and wanna know how to do it properly. Thanks.
My ugly solution: 

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://www.bestbuy.com/site/searchpage.jsp?_&ks=960&sc=Global&list=y&usc=All%20Categories&type=page&id=pcat17071&iht=n&seeAll=&cp=1&browsedCategory=pcmcat138500050001&st=pcmcat138500050001_categoryid$abcat0502000&qp=soldby_facet%3DSold%20By~Best%20Buy^condition_facet%3DCondition~New^currentprice_facet%3DPrice~%24250%20-%20%24499.99^currentprice_facet%3DPrice~%24200%20-%20%24249.99^currentprice_facet%3DPrice~%24150%20-%20%24199.99^currentprice_facet%3DPrice~%24100%20-%20%24149.99")

soup = BeautifulSoup(html.read())

laptop_rows = soup.find_all("div", {"class":"row"})

names=[]
prices=[]

for row in laptop_rows:
name = row.find("a", {"data-rank":"pdp"});
names.append(name)

for row in laptop_rows:
price = row.find("div", {"class":"medium-item-price"})
prices.append(price)

Reply all
Reply to author
Forward
0 new messages