获取 iterlinks 的“'NoneType' 对象不可迭代”错误
Getting " 'NoneType' object is not iterable" error for iterlinks
我在下面的代码中遇到了 iterlinks 的“'NoneType' object is not iterable”错误。有人可以帮忙吗?
from lxml import html
source=urllib.request.urlopen("http://google.com").read()
tree=html.document_fromstring(source)
for i in tree.iterlinks:
print(i)
您应该在 for
循环中使用 tree.iterlinks()
:
for i in tree.iterlinks():
print(i)
输出:
(<Element style at 0x7f9e6e41ca48>, None, '/images/nav_logo229.png', 1054)
(<Element link at 0x7f9e6e406db8>, 'href', '/images/branding/product/ico/googleg_lodp.ico', 0)
...
我在下面的代码中遇到了 iterlinks 的“'NoneType' object is not iterable”错误。有人可以帮忙吗?
from lxml import html
source=urllib.request.urlopen("http://google.com").read()
tree=html.document_fromstring(source)
for i in tree.iterlinks:
print(i)
您应该在 for
循环中使用 tree.iterlinks()
:
for i in tree.iterlinks():
print(i)
输出:
(<Element style at 0x7f9e6e41ca48>, None, '/images/nav_logo229.png', 1054)
(<Element link at 0x7f9e6e406db8>, 'href', '/images/branding/product/ico/googleg_lodp.ico', 0)
...