Answer the question
In order to leave comments, you need to log in
How to parse strings in Python?
Good time!
Tell me how to parse the desired text from strings?
Help a newbie, he broke his head!
Given:
<tr>
<td>
<br/><br/>
<i class="icon icon-user" data-selector=".icon" title="Автор"></i> Барышева Олеся<br/>
<i class="icon icon-support" data-selector=".icon" title="E-mail"></i> [email protected]<br/>
<i class="icon icon-phone" data-selector=".icon" title="Телефон"></i> 89188565504<br/>
</td>
</tr>
Answer the question
In order to leave comments, you need to log in
soup = BeautifulSoup(html)
author_text = soup.find('i',{'class':'icon icon-user'})
email_text = soup.find('i',{'class':'icon icon-support'})
phone_text = soup.find('i',{'class':'icon icon-phone'})
print(author_text.next)
print(email_text.next)
print(phone_text.next)
Пыльнев Анатолий
[email protected]
89055663563
from bs4 import BeautifulSoup
html="""
<tr>
<td>
<br/><br/>
<i class="icon icon-user" data-selector=".icon" title="Автор"></i> Барышева Олеся<br/>
<i class="icon icon-support" data-selector=".icon" title="E-mail"></i> [email protected]<br/>
<i class="icon icon-phone" data-selector=".icon" title="Телефон"></i> 89188565504<br/>
</td>
</tr>
"""
soup = BeautifulSoup(html)
my_text = soup.find('td')
print(my_text.get_text().split())
['Барышева', 'Олеся', '[email protected]', '89188565504']
Барышева Олеся
[email protected]
89188565504
from bs4 import BeautifulSoup
html="""
<tr>
<td>
<br/><br/>
<i class="icon icon-user" data-selector=".icon" title="Автор"></i> Барышева Олеся<br/>
<i class="icon icon-support" data-selector=".icon" title="E-mail"></i> [email protected]<br/>
<i class="icon icon-phone" data-selector=".icon" title="Телефон"></i> 89188565504<br/>
</td>
</tr>
<tr>
<td>
<br/><br/>
<i class="icon icon-user" data-selector=".icon" title="Автор"></i> Иван Иванович<br/>
<i class="icon icon-support" data-selector=".icon" title="E-mail"></i> [email protected]<br/>
<i class="icon icon-phone" data-selector=".icon" title="Телефон"></i> 232321113312<br/>
</td>
</tr>
<tr>
<td>
<br/><br/>
<i class="icon icon-user" data-selector=".icon" title="Автор"></i> Темный лорд<br/>
<i class="icon icon-support" data-selector=".icon" title="E-mail"></i> [email protected]<br/>
<i class="icon icon-phone" data-selector=".icon" title="Телефон"></i> 80002111122<br/>
</td>
</tr>
"""
soup = BeautifulSoup(html)
my_text = soup.findAll('td')
for text in my_text:
print(text.get_text().split())
['Барышева', 'Олеся', '[email protected]', '89188565504']
['Иван', 'Иванович', '[email protected]', '232321113312']
['Темный', 'лорд', '[email protected]', '80002111122']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question