Skip to content

Python: Getting page title

# Get the HTML page content
from urllib import request
html = request.urlopen("https://silveiraneto.net").read()

# Get the title tag
from bs4 import BeautifulSoup
title = BeautifulSoup(html, 'html.parser').find('title')

print(title.string)

This uses the XML/HTML library BeautifulSoup . This could also be done using regex but playing with HTML and regex is usually a bad idea.

Published inenglish

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *