我正在使用此(https://github.com/thibauts/duckduckgo)模块来搜索duckduckgo搜索结果:
>>> import duckduckgo
>>> for links in duckduckgo.search('Yellow Chris Martin',max_results=20):
... print links
在输出中我得到搜索结果,似乎有 重复4次相同的链接
输出:
http://www.youtube.com/watch?v=ZTEKsbLl64w
http://www.youtube.com/watch?v=ZTEKsbLl64w
http://www.youtube.com/watch?v=ZTEKsbLl64w
http://www.youtube.com/watch?v=ZTEKsbLl64w
https://en.wikipedia.org/wiki/Yellow_(Coldplay_song)
https://en.wikipedia.org/wiki/Yellow_(Coldplay_song)
https://en.wikipedia.org/wiki/Yellow_(Coldplay_song)
https://en.wikipedia.org/wiki/Yellow_(Coldplay_song)
http://www.youtube.com/watch?v=1MwjX4dG72s
http://www.youtube.com/watch?v=1MwjX4dG72s
http://www.youtube.com/watch?v=1MwjX4dG72s
http://www.youtube.com/watch?v=1MwjX4dG72s
如何修复此问题并获得与使用搜索引擎时相同的结果。
答案 0 :(得分:1)
您可以使用将duckduckgo对象转换为列表,然后使用set():
count = 10
while( set(list(duckduckgo.search('Yellow Chris Martin',max_results=count)) ) < some_val ):
count = count + 1
for links in set(list(duckduckgo.search('Yellow Chris Martin',max_results=count)) :
print links