自动构建搜索词



我正在做一些抓取,但我希望自动构建一个广泛的关键字列表。我设计的一种既不方便也不方便的方法如下:

def build_search_terms():
words1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
words2 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for word in words2:
result = words1[0] + word
words2.pop(0)
search_for(result)

我试图做的是创建一个函数,该函数将aa吐出到az,然后babz,然后cacz,依此类推。

以前有人解决这个问题吗?

有没有更有效的方法可以做到这一点?

您可以获得所需的输出,如下所示:

def build_search_terms():
words_list = []
words = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in words:
for j in words:
yield i + j

并将其用作

for word in build_search_terms():
print(word)

def build_search_terms():
words = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
return (i +j for i in words for j in words)

并将其用作

words = build_search_terms()
print(next(words))  # 'aa'
print(next(words))  # 'ab'
print(next(words))  # 'ac'
....

相关内容

  • 没有找到相关文章

最新更新