Issue
<strong><i class="fas fa-id-card-alt"> </i> I want this text to be copied</strong>
string = bla.find("strong").string
gives None
Solution
In this case, you'll need to create a BeautifulSoup
element:
bla = '<strong><i class="fas fa-id-card-alt"> </i> I want this text to be copied</strong>'
soup = BeautifulSoup(bla, 'html.parser')
Next, you can use find()
passing your desired tag, in this case <strong>
, then use get_text()
to get your contents:
string = soup.find('strong').get_text()
The result will be:
' I want this text to be copied'
You can use the String method strip()
to... strip the whitespaces:
>>> string.strip()
'I want this text to be copied'
Answered By - trinaldi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.