我有下一个代码:
for table in soup.findAll("table","tableData"):
for row in table.findAll("tr"):
data = row.findAll("td")
url = data[0].a
print type(url)
我得到下一个输出:
<class 'bs4.element.Tag'>
这意味着,该 url 是类 Tag 的对象,我可以从该对象中获取属性字节。但是如果我替换print type(url)
为print url['href']
我得到下一个回溯
Traceback (most recent call last):
File "baseCreator.py", line 57, in <module>
createStoresTable()
File "baseCreator.py", line 46, in createStoresTable
print url['href']
TypeError: 'NoneType' object has no attribute '__getitem__'
怎么了?以及如何获得 href 属性的值。