from bs4 import BeautifulSoup

html = '''
<html>
<head>
    <meta charset="UTF-8">
    <title>Beautiful Soup演示</title>
    <tag1><xyz><b></b></xyz></tag1>
</head>
<body>
<div>
    <ul>
        <li class="item1" value = "hello world">
            <a href="https://geekori.com"> 
                geekori.com
            </a>
        </li>
        <li class="item2"><a href="https://www.jd.com"> 京东商城</a></li>

    </ul>
</div>
</body>
</html>
'''

soup = BeautifulSoup(html,'lxml')
print(soup.a.parent)
print(soup.a.parent['class'])

print(soup.a.parents)
for parent in soup.a.parents:
    print('<',parent.name,'>')



d869b6a3070391d348e02273f34d960db191250d
<mask token>

<mask token>
print(soup.a.parent)
print(soup.a.parent['class'])
print(soup.a.parents)
for parent in soup.a.parents:
    print('<', parent.name, '>')

<mask token>
html = """
<html>
<head>
    <meta charset="UTF-8">
    <title>Beautiful Soup演示</title>
    <tag1><xyz><b></b></xyz></tag1>
</head>
<body>
<div>
    <ul>
        <li class="item1" value = "hello world">
            <a href="https://geekori.com"> 
                geekori.com
            </a>
        </li>
        <li class="item2"><a href="https://www.jd.com"> 京东商城</a></li>

    </ul>
</div>
</body>
</html>
"""
soup = BeautifulSoup(html, 'lxml')
print(soup.a.parent)
print(soup.a.parent['class'])
print(soup.a.parents)
for parent in soup.a.parents:
    print('<', parent.name, '>')

from bs4 import BeautifulSoup
html = """
<html>
<head>
    <meta charset="UTF-8">
    <title>Beautiful Soup演示</title>
    <tag1><xyz><b></b></xyz></tag1>
</head>
<body>
<div>
    <ul>
        <li class="item1" value = "hello world">
            <a href="https://geekori.com"> 
                geekori.com
            </a>
        </li>
        <li class="item2"><a href="https://www.jd.com"> 京东商城</a></li>

    </ul>
</div>
</body>
</html>
"""
soup = BeautifulSoup(html, 'lxml')
print(soup.a.parent)
print(soup.a.parent['class'])
print(soup.a.parents)
for parent in soup.a.parents:
    print('<', parent.name, '>')

from bs4 import BeautifulSoup

html = '''
<html>
<head>
    <meta charset="UTF-8">
    <title>Beautiful Soup演示</title>
    <tag1><xyz><b></b></xyz></tag1>
</head>
<body>
<div>
    <ul>
        <li class="item1" value = "hello world">
            <a href="https://geekori.com"> 
                geekori.com
            </a>
        </li>
        <li class="item2"><a href="https://www.jd.com"> 京东商城</a></li>

    </ul>
</div>
</body>
</html>
'''

soup = BeautifulSoup(html,'lxml')
print(soup.a.parent)
print(soup.a.parent['class'])

print(soup.a.parents)
for parent in soup.a.parents:
    print('<',parent.name,'>')


