Skip to content

Instantly share code, notes, and snippets.

@tylerburdsall
Last active September 6, 2017 23:17
Show Gist options
  • Save tylerburdsall/5de43d1717a4ab54f8d207d8e06e8c53 to your computer and use it in GitHub Desktop.
Save tylerburdsall/5de43d1717a4ab54f8d207d8e06e8c53 to your computer and use it in GitHub Desktop.
from urllib.request import urlopen
from bs4 import BeautifulSoup
website = 'https://saltandstraw.com/flavors/'
page = urlopen(website)
soup = BeautifulSoup(page, 'html.parser')
results = soup.find('section', attrs={'class':'content-area clear portland'}).findAll('div', attrs={'class':'entry-title'})
flavors = []
for title in results:
flavors.append(title.text)
count = len(flavors)
flavors_and_links = []
links = soup.find('section', attrs={'class':'content-area clear portland'}).findAll('a', href=True)
for i in range(count):
flavors_and_links.append({'Flavor': flavors[i], 'Link': links[i]['href']}) # new change
# new code below
descs = [] # will hold our descriptions
for i in range(count):
link = flavors_and_links[i]['Link']
page = urlopen(link)
soup = BeautifulSoup(page, 'html.parser')
result = soup.find('span', attrs={'style':'font-weight: 400;'})
descs.append(result.text)
# print everything out
for i in range(count):
print("****")
print(flavors_and_links[i]['Flavor'])
print("****")
print(descs[i] + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment