Regex within html tags

前端 未结 5 526
孤独总比滥情好
孤独总比滥情好 2021-01-24 10:19

I would like to parse the HD price from the following snipper of HTML. I am only have fragments of the html code, so I cannot use an HTML parser for this.



        
5条回答
  •  清酒与你
    2021-01-24 10:25

    You've asked for a regular expression here, but it's not the right tool for parsing HTML. Use BeautifulSoup for this.

    >>> from bs4 import BeautifulSoup
    >>> html = '''
    
    View In iTunes £19.99
    • HD Version
    • ''' >>> soup = BeautifulSoup(html) >>> val = soup.find('span', {'class':'price'}).text >>> print val[1:] 19.99

提交回复
热议问题