Extract part of a regex match

前端 未结 9 1957
北海茫月
北海茫月 2020-11-22 13:01

I want a regular expression to extract the title from a HTML page. Currently I have this:

title = re.search(\'.*\', html, re.IGNOR         


        
9条回答
  •  一个人的身影
    2020-11-22 13:43

    Use ( ) in regexp and group(1) in python to retrieve the captured string (re.search will return None if it doesn't find the result, so don't use group() directly):

    title_search = re.search('(.*)', html, re.IGNORECASE)
    
    if title_search:
        title = title_search.group(1)
    

提交回复
热议问题