首页 > 解决方案 > Extracting a tag value in Beautiful Soup

问题描述

I am parsing a html document using beautiful soup in python.

I came across a tag like this

div class="_3auQ3N">\u20b9<!-- -->1,990</div>

\u20bp represents currency symbol and 1,990 is the price.

I want to know how can I extract these values into two different Strings (or values)?

标签: pythonhtmlbeautifulsoup

解决方案


>>> soup = BeautifulSoup('<div class="_3auQ3N">\u20b9<!-- -->1,990</div>', 'lxml')
>>> list(soup.div.strings)
['₹', '1,990']

推荐阅读