'How to get value from bs4 resultset in beautifulsoap?
I want to get all title value from this bs4 resultset?
[<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>]
How can I get all value of title like 16.3.2022 15:22:44 , 16.3.2022 15:32:01 etc?
Solution 1:[1]
I'm getting the digits value as follows:
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)
Output:
16.3.2022 15:22:44 , 16.3.2022 15:32:01
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | F.Hoque |
