How do I scrape the "title" of a webpage (i.e. the text that shows up on the tab bar)

How do I scrape the "title" of a webpage (i.e. the text that shows up on the tab bar)?

For example, look at this webpage.

Its "title" or webpage is

datetime - How to get the current time in Python - Stack Overflow

This string does not appear anywhere on the webpage itself as an element. So how would I extract the title? Note: I could manually do it by investigating visible elements on the page such as tags, but there are some webpages where the title doesn't show up at all on the webpage other than on the tab bar, so I'm trying to figure out how to get those.

A page's title is located within the <title> tag, which is standard on almost all web pages. Also, the <title> tag is usually located within a <head> tag, so you can extract the text with:

Type: Text
Selector: head title

Ref: HTML title tag

1 Like