Last active
September 6, 2017 23:17
-
-
Save tylerburdsall/5de43d1717a4ab54f8d207d8e06e8c53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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