[Python] Get the attribute data by another attribute beautifulsoup

Discussão em 'Python' iniciado por Stack, Agosto 25, 2025.

  1. Stack

    Stack Membro Participativo

    I want to parse the HTML like this below with beautiful soup

    .
    .
    <meta property="og:image" content="https://test.com/test.jp" />
    <meta property="og:description" content="mydescription" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="content-style-type" content="text/css" />
    .
    .


    With this script,

    bs = BeautifulSoup(response.text, 'html.parser')
    metas = bs.find_all('meta')


    I can get the array of meta tag

    However I want to get the attribute content such as https://test.com/test.jp by the key attribute property="og:image"

    Like

    metas.find('property:"og:image"').content


    How can I make it ?

    Continue reading...

Compartilhe esta Página