Jun-06-2018, 12:15 PM
The whole thing is messy as pointed out bye @buran.
It's not code that we can run,missing imports and call to function.
Just to show a quick test,with code that can be run(no missing parts).
Take out name of featured product,
If get error in this short code,it's easy to see what's wrong.
Then can structure in functions(not to much code in one function).
It's not code that we can run,missing imports and call to function.
attrs={"class": "buy"}Do you find a
class='buy'
on that site?Just to show a quick test,with code that can be run(no missing parts).
Take out name of featured product,
class_='price'
will take out price.import requests from bs4 import BeautifulSoup url = 'http://www.infantree.net/shop/' response = requests.get(url) soup = BeautifulSoup(response.content, 'lxml') #print(soup) featured = soup.find('section', class_="featured span") li = featured.find_all('li') for item in li: print(item.find('div', class_='name').text.strip())
Output:THE FIRST YEARS Bottle Warmer and Cooler
THE FIRST YEARS Steam Sterilizer
AMEDA Store'N Pour Breast Milk Storage Bags
AMEDA Lactaline Personal Breastpump
LASCAL Kiddy Guard Accent - Black
Do small test like this first to make sure that all work.If get error in this short code,it's easy to see what's wrong.
Then can structure in functions(not to much code in one function).