如何从 BeautifulSoup 中的 bs4 结果集中获取价值?
How to get value from bs4 resultset in beautifulsoap?
我想从这个 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 等?
我得到的数字值如下:
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:01
我想从这个 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 等?
我得到的数字值如下:
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:01