Beautifulsoup, bot için kullanılan bir Python kütüphanesidir. Bu güçlü python aracı, HTML web sayfalarını değiştirmek için de kullanılabilir. Bu makale, nicesoup'un bir div'i ve içeriğini kimliğine göre ayıklamak için nasıl kullanılabileceğini gösterir. Bunun için modülün find() işlevi, div'i kimliğine göre bulmak için kullanılır.
#importing module
from bs4 import BeautifulSoup
markup = '''<html><body><div id="container">Div Content</div></body></html>'''
soup = BeautifulSoup(markup, 'html.parser')
#finding the div with the id
div_bs4 = soup.find('div', id = "container")
print(div_bs4.string)
Diğer örneğimiz
#importing module
from bs4 import BeautifulSoup
markup =markup = """
<!DOCTYPE>
<html>
<head><title>Example</title></head>
<body>
<p>
Nested div
</p>
<div id="first"> Div with ID first
<div id="second"> Div with id second
</div>
</div>
</body>
</html>
"""
# parsering string to HTML
soup = BeautifulSoup(markup, 'html.parser')
#finding the div with the id
div_bs4 = soup.find('div', id = "second")
print(div_bs4.string)
Output: