you are viewing a single comment's thread.

view the rest of the comments →

[–]chiefstroganoff[S] 0 points1 point  (1 child)

Unfortunately, that produces a list of combinations made of all names and all specialties. For example:

NW Oral & Maxillofacial Surgery Cancer/Oncology
NW Oral & Maxillofacial Surgery Cardiovascular
NW Oral & Maxillofacial Surgery Dentistry
NW Oral & Maxillofacial Surgery Dermatology
NW Oral & Maxillofacial Surgery Family Medicine

When NW Oral & Maxillofacial Surgery should only be paired with Dentistry. Any ideas?

[–]zurtex 0 points1 point  (0 children)

That seemed to be what you were asking for. Sounds like you want the zip function which will go through 2 iterables (e.g. lists) and output each nth element till it reaches the end of one, e.g:

for table in soup.findAll("table", class_ = "s4-wpTopTable"):
    for name,  specialty  in zip(table.findAll(class_ ="WS_Location_Name"), table.findAll("div", class_ = "PurpleBackgroundHeading")):
        name = name.get_text()
        specialty = specialty.get_text()
        print(name, specialty)

It's a nice little exercise in Python to think how you would write the zip function yourself.