How to get page title in requests

后端 未结 5 1596
伪装坚强ぢ
伪装坚强ぢ 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 22:56

    Regex with lookbehind and lookforward:

    re.search('(?<=).+?(?=)', mytext, re.DOTALL).group().strip()
    

    re.DOTALL because title can have a new line character \n

提交回复
热议问题