Python: BeautifulSoup - get an attribute value based on the name attribute

后端 未结 7 1787
抹茶落季
抹茶落季 2020-11-27 10:38

I want to print an attribute value based on its name, take for example


I want to do something

7条回答
  •  渐次进展
    2020-11-27 11:33

    The following works:

    from bs4 import BeautifulSoup
    
    soup = BeautifulSoup('', 'html.parser')
    
    metas = soup.find_all("meta")
    
    for meta in metas:
        print meta.attrs['content'], meta.attrs['name']
    

提交回复
热议问题