Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不必要的重复项美化循环组_Python_Web Scraping_Beautifulsoup_Nested Loops - Fatal编程技术网

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)

使用集合存储数据,然后写入内容您有如何循环集合的示例吗?在哪里连接刚设置。添加使用集合存储数据,然后写入内容您有如何循环集合的示例吗?在哪里连接刚设置。添加