<meta itemprop="price" content="4.05"/>
这是我需要从中提取4.05
的HTML。
我在使用BeautifulSoup和Python。
我还需要使用itemprop="price"
,因为我有多个<meta content="x"/>
soup.find("meta", {"itemprop":"price"})["content"]
4.05
答案 0 :(得分:2)
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
答案 1 :(得分:1)
>>> 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'
>>>