我不認爲我瞭解如何檢查數組索引存在...快譯通指數在BeautifulSoup和「如果x在快譯通」
for tag in soup.findAll("input"):
print tag['type']
if 'type' in tag:
print "b"
輸出:
2255
text
hidden
text
text
text
Traceback (most recent call last):
File "/home//workspace//src/x.py", line 268, in <module>
print tag['type']
File "/home//workspace//src/BeautifulSoup.py", line 601, in __getitem__
return self._getAttrMap()[key]
KeyError: 'type'
爲什麼它不會輸出'b'?