INNER CODE UNIT · Python
extract_title
essamamdani/search-result-scraper-markdown · main.py:139
def extract_title(html_content):
if html_content:
soup = BeautifulSoup(html_content, 'html.parser')
title = soup.find("title")
return title.string.replace(" - YouTube", "") if title else 'No title'
return 'No title'
def clean_html(html):
soup = BeautifulSoup(html, 'html.parser')
# Remove all script, style, and other unnecessary elements
for script_or_style in soup(["script", "style", "header", "footer", "noscript", "form", "input", "textarea", "select", "option", "button", "svg", "iframe", "object", "embed", "applet", "nav", "navbar"]):
script_or_style.decompose()
# remove ids "layers"
ids = ['layers']
for id_ in ids: