(使用python 3.3.2)嗨,我试图为文本云做一个爬行函数,它将进入链接列表并理想地返回一个列表函数的输出列表中的每个元素。然而,我卡住使用打印功能,打印(二),而不是实际返回我想要的。在我的for循环中,我将如何返回从print(b)语句中获得的所有内容。它可以全部在一个列表中或以某种方式编译。谢谢:) TL;博士:我怎么回所有的东西我从得到循环如何从for循环返回每个值
def crawl():
linkList = inputFunction()[1:][0] #makes a list of a bunch of URL's
for i in range(len(linkList)):
print(i)
t = getHTML(linkList[i]) #getHTML returns tuple of text in the input URL
alreadyCrawl = alreadyCrawl + list(linkList[i]) #ignore this
t = list(t)
b = counting(t) #makes dictionary of word counts
print(b)
return
也可以考虑在linkList'使用'用于链路而不是'为i的范围(LEN(链表)):... LINKLIST [I]'。 – Hyperboreus
它通常值得避免像范围内的我(len(linkList)):' - 它可以更清楚地写成:对于i,枚举项(linkList):'(如果你不需要实际上使用'i',作为'linkList:'中的项目)。 – lvc