我想根据它的名字打印属性值的属性值,举个例子的Python:BeautifulSoup - 获得基于的name属性
<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']
上面的代码给出,我相信这是因为BeatifulSoup使用了名称,所以它不能用作关键字参数。
我怎么能做到这一点,如果我想找到所有实例,也就是现在,soup.find( “元”,{ “名”: “城市”})['content']给出了第一个结果,但是说在汤中有另一行是 overflowname
旧的问题,但这里有一个简单的解决方案,以防其他人来找它:'soup.findAll(“meta”,{“name”:“City”})['content']'。这将返回所有的事件。 –