(使用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