в fucntion getLink(urls)
, я return (cloud,parent,children)
в основной функции, у меня есть (cloud,parent,children) = getLink(urls)
и я получил ошибку этой линии: TypeError: объект «NoneType» не итерацияя получил aTypeError: объект «NoneType» не итерации
родителями и детьми являются все list
http ссылки. так как он не может вставить их здесь, родительский список содержит около 30 ссылок; children - список содержит около 30 предметов, каждый элемент - около 10-100 ссылок, которые делятся на «,».
облако список содержит около 100 слов, как это: [ 'официальный магазин', 'Java-апплеты Центр', 'О Google', 'История веб-поиска' .....]
Я знаю didnot почему я получаю сообщение об ошибке. Что-то не так в прохождении параметра? Или потому, что список занимает слишком много места?
#crawler url: read webpage and return a list of url and a list of its name
def crawler(url):
try:
m = urllib.request.urlopen(url)
msg = m.read()
....
return (list(set(list(links))),list(set(list(titles))))
except Exception:
print("url wrong!")
#this is the function has gone wrong: it throw an exception here, also the error I mentioned, also it will end while before len(parent) reach 100.
def getLink(urls):
try:
newUrl=[]
parent = []
children =[]
cloud =[]
i=0
while len(parent)<=100:
url = urls[i]
if url in parent:
i += 1
continue
(links, titles) = crawler(url)
parent.append(url)
children.append(",".join(links))
cloud = cloud + titles
newUrl= newUrl+links
print ("links: ",links)
i += 1
if i == len(urls):
urls = list(set(newUrl))
newUrl = []
i = 0
return (cloud,parent,children)
except Exception:
print("can not get links")
def readfile(file):
#not related, this function will return a list of url
def main():
file='sampleinput.txt'
urls=readfile(file)
(cloud,parent,children) = getLink(urls)
if __name__=='__main__':
main()
Вы можете иметь другие 'return' в функции или неявной' None' как возвращаемое значение. – Matthias