Reputation: 373
<meta itemprop="price" content="4.05"/>
Here's my HTML that I need to extract 4.05
from.
I'm using BeautifulSoup with Python.
I also need to use itemprop="price"
because I have more than one <meta content="x"/>
soup.find("meta", {"itemprop":"price"})["content"]
4.05
Upvotes: 1
Views: 214
Reputation: 739
>>> from bs4 import BeautifulSoup
>>> text = '<meta itemprop="price" content="4.05"/>'
>>> soup = BeautifulSoup(text)
>>> soup
<html><head><meta content="4.05" itemprop="price"/></head></html>
>>> soup.meta
<meta content="4.05" itemprop="price"/>
>>> soup.meta["content"]
'4.05'
>>>
Upvotes: 1
Reputation: 180391
html = '<meta itemprop="price" content="4.05"/>'
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
soup.find("meta")["content"]
4.05
soup.meta["content"]
4.05
Upvotes: 2