Regex within html tags

前端 未结 5 562
孤独总比滥情好
孤独总比滥情好 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:33

    You can still parse using BeautifulSoup, you don't need the full html:

    from bs4 import BeautifulSoup
    html="""
    
    View In iTunes £19.99
    • HD Version
    • """ soup = BeautifulSoup(html) sp = soup.find(attrs={"class":"price"}) print sp.text[1:] 19.99

提交回复
热议问题