我想从这个bs4结果集中获得所有的标题值?
[<span class="zaman" title="16.3.2022 15:22:44">1 hf.</span>, <span class="hide zaman pull-right ml-5 mt--1">( Mesaj Silindi )</span>,<span class="zaman" title="16.3.2022 15:32:01">1 hf.</span>, <span class="hide zaman pull-right ml-5 mt--1">( Mesaj Silindi )</span>]我怎样才能得到所有的标题价值,如16.3.2022 15:22:44,16.3.2022 15:32:01等等?
发布于 2022-03-23 23:32:59
我得到的数字值如下:
html='''
<span class="zaman" title="16.3.2022 15:22:44">
1 hf.
</span>
,
<span class="hide zaman pull-right ml-5 mt--1">
( Mesaj Silindi )
</span>
,
<span class="zaman" title="16.3.2022 15:32:01">
1 hf.
</span>
,
<span class="hide zaman pull-right ml-5 mt--1">
( Mesaj Silindi )
</span>
'''
from bs4 import BeautifulSoup
soup= BeautifulSoup(html,'html.parser')
#print(soup.prettify())
value = [x.get('title') for x in soup.find_all('span', class_="zaman")]
value=value[0]+ ' , ' + value[2]
print(value)输出:
16.3.2022 15:22:44 , 16.3.2022 15:32:01https://stackoverflow.com/questions/71594956
复制相似问题