How to get page title in requests

后端 未结 5 1614
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 22:53

What would be the simplest way to get the title of a page in Requests?

r = requests.get(\'http://www.imdb.com/title/tt0108778/\')
# ? r.title
Friends (TV Ser         


        
5条回答
  •  再見小時候
    2020-12-28 23:12

    You could use beautifulsoup to parse the HTML.

    Install it using pip install beautifulsoup4

    >>> import requests
    >>> r = requests.get('http://www.imdb.com/title/tt0108778/')
    >>> import bs4
    >>> html = bs4.BeautifulSoup(r.text)
    >>> html.title
    Friends (TV Series 1994–2004) - IMDb
    >>> html.title.text
    u'Friends (TV Series 1994\u20132004) - IMDb'
    

提交回复
热议问题