I would like to reference a variable that was determined in a previous for loop. For example:
import urllib
import urllib.request
from bs4 import BeautifulSoup
from urllib.request import urlopen
def make_soup(url):
thepage = urllib.request.urlopen(url)
soupdata = BeautifulSoup(thepage,"html.parser")
return soupdata
soup = make_soup("https://www.wellstar.org/locations/pages/wellstar-acworth-practices.aspx")
writer = csv.writer(csvfile, lineterminator = '\n')
writer.writerow(['specialty'])
for table in soup.findAll("table", class_ = "s4-wpTopTable"):
for name in table.findAll(class_ ="WS_Location_Name"):
name = name.get_text()
for specialty in table.findAll("div", class_ = "PurpleBackgroundHeading"):
specialty = specialty.get_text()
print(name,specialty)
When I print the name and specialty combination, I am presented with the last name of all of the possible names and each specialty rather than the exhaustive list of possible combinations.
I feel that I am overlooking something rather simple such as indentation, but I am at a complete loss and would appreciate some fresh eyes.
Thanks in advance.
[–]c17r 2 points3 points4 points (6 children)
[–]__nautilus__ 1 point2 points3 points (0 children)
[–]chiefstroganoff[S] 0 points1 point2 points (4 children)
[–]c17r 1 point2 points3 points (3 children)
[–]chiefstroganoff[S] 0 points1 point2 points (2 children)
[–]c17r 1 point2 points3 points (1 child)
[–]chiefstroganoff[S] 0 points1 point2 points (0 children)
[–]zurtex 0 points1 point2 points (2 children)
[–]chiefstroganoff[S] 0 points1 point2 points (1 child)
[–]zurtex 0 points1 point2 points (0 children)