最佳答案
我想根据它的名称打印一个属性值,例如
<META NAME="City" content="Austin">
我想做这样的事
soup = BeautifulSoup(f) # f is some HTML containing the above meta tag
for meta_tag in soup("meta"):
if meta_tag["name"] == "City":
print(meta_tag["content"])
上面的代码给出了一个 KeyError: 'name'
,我相信这是因为 BeatifulSoup 使用了 name,所以它不能用作关键字参数。