How can I retrieve the page title of a webpage using Python?

后端 未结 11 1770
南笙
南笙 2020-12-07 08:55

How can I retrieve the page title of a webpage (title html tag) using Python?

11条回答
  •  暖寄归人
    2020-12-07 09:37

    Use soup.select_one to target title tag

    import requests
    from bs4 import BeautifulSoup as bs
    
    r = requests.get('url')
    soup = bs(r.content, 'lxml')
    print(soup.select_one('title').text)
    

提交回复
热议问题