1

我正在使用这个(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

如何解决此问题并获得与使用搜索引擎时相同的结果。

4

1 回答 1

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
于 2016-06-20T08:45:14.807 回答