Python 不必要的重复项美化循环组
通过以下代码,我能够提取位置类型(医院、紧急护理等)、位置名称及其地址。然而,我收到了一堆复制品。我怎样才能消除重复,并且只保留每个位置的一个记录Python 不必要的重复项美化循环组,python,web-scraping,beautifulsoup,nested-loops,Python,Web Scraping,Beautifulsoup,Nested Loops,通过以下代码,我能够提取位置类型(医院、紧急护理等)、位置名称及其地址。然而,我收到了一堆复制品。我怎样才能消除重复,并且只保留每个位置的一个记录 from bs4 import BeautifulSoup import csv file = open("/home/daniel/Downloads/wellstar.html") soup = BeautifulSoup(file,"html.parser") types = soup.findAll("h3",class_="WebFon
from bs4 import BeautifulSoup
import csv
file = open("/home/daniel/Downloads/wellstar.html")
soup = BeautifulSoup(file,"html.parser")
types = soup.findAll("h3",class_="WebFont SpotBodyGreen")
names = soup.findAll("div",class_="PurpleBackgroundHeading")
addresses = soup.findAll("div",class_="WS_Location")
locations_saved=""
for type in types:
locations=""
for name in names:
for address in addresses:
locations=locations+"\n"+type.text+name.text+address.text
locations_saved=locations_saved+"\n"+locations[1:]
print(locations_saved)
使用集合存储数据,然后写入内容您有如何循环集合的示例吗?在哪里连接刚设置。添加使用集合存储数据,然后写入内容您有如何循环集合的示例吗?在哪里连接刚设置。添加