# import beautifulsoup here
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>
​
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;and they lived at the bottom of a well.</p>
​
<p class="story">...</p>
"""

soup = BeautifulSoup(html_doc, 'lxml')

# print(soup.prettify())

# print the href attribute of Lacie
for para in soup.find_all('a', {'id': 'link2'}):
    print(para['href'])
# print text of the <a> tag with the name Tillie on it
for para2 in soup.find_all('a', {'id': 'link3'}):
    print(para2.text)
# print the id of Elsie
for para3 in soup.find_all('a', class_='sister'):
    elsie = 'link1'
    result = para3.get('id')
    if result == elsie:
        print(elsie)


# ----------------Diffuculty: Hard---------------------
# print the contents of the tags with the class 'story'
# for story in soup.find_all('p', class_='story'):
#     summary = story.get_text().replace('\n', ' ')
#     print(summary)

story = soup.find_all('p', class_='story')

content = [summary.text.replace('\n', '') for summary in story]
print(' '.join(content)) 