gpt4 book ai didi

python - 简单的网络爬虫我需要消除数组中存在的重复 URL

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:40 25 4
gpt4 key购买 nike

我正在使用数组来存储 URL,我需要消除在数组中多次出现的 URL,因为我不需要再次抓取相同的 URL:

self.level = []  # array where the URL are present 
for link in self.soup.find_all('a'):
self.level.append(link.get('href'))
print(self.level)

我需要在抓取此 URL 之前消除重复的 URL。

最佳答案

维护 set网址:

self.level = set()
for link in self.soup.find_all('a'):
self.level.add(link.get('href'))

关于python - 简单的网络爬虫我需要消除数组中存在的重复 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com