需要从span id中检索数据的指导

时间:2018-02-23 01:12:07

标签: python

希望得到一些帮助,我需要废弃id和温度。我尝试了几件事,但我无法做到可以有人帮忙。我正在使用BeautifulSoup获取信息然后打印出来

<span id="root.content.BoundLabel12.text">21.1 ºC</span> 

1 个答案:

答案 0 :(得分:0)

>>> from bs4 import BeautifulSoup
... 
... soup = BeautifulSoup(
...     '<span id="root.content.BoundLabel12.text">21.1 ºC</span>'
... )
>>> span_id = soup.span['id']
>>> span_id
'root.content.BoundLabel12.text'
>>> temperature = soup.span.text
>>> temperature
'21.1 ºC'