我不想收到两次地址错误 TypeError:不可损坏类型:“list” 所以我假设这条线 allLinks=set() 是错误的,我必须使用元组而不是列表,对吗?在
这是我的准则:
import requests
from bs4 import BeautifulSoup as soup
def get_emails(_links:list):
for i in range(len(_links)):
new_d = soup(requests.get(_links[i]).text, 'html.parser').find_all('a', {'class':'my_modal_open'})
if new_d:
yield new_d[-1]['title']
start = 20
while True:
d = soup(requests.get('http://www.schulliste.eu/type/gymnasien/?bundesland=&start={page_id}'.format(page_id=start)).text, 'html.parser')
results = [i['href'] for i in d.find_all('a')][52:-9]
results = [link for link in results if link.startswith('http://')]
next_page=d.find('div', {'class': 'paging'}, 'weiter')
if next_page:
start+=20
else:
break
allLinks= set()
if results not in allLinks:
print(list(get_emails(results)))
allLinks.add(results)
我成功了,但是我仍然收到重复的电子邮件。在
有人知道为什么吗?在
您试图将整个电子邮件列表作为一个条目添加到
set
中。在您需要的是将实际电子邮件添加到单独的
set
条目中。在问题在于:
它将整个
^{pr2}$results
列表作为一个元素添加到set
中,但这不起作用。改用这个:这将使用},但是每个元素都是{}中的一个单独的条目。在
list
中的元素更新{相关问题 更多 >
编程相关推荐