Learner
Learner

Reputation: 691

Get text inside HTML doc element using python

I need to get the text inside the two elements. This is HTML doc string

string= """<span class="buddyName0">adam</span></td></tr><tr><td> Dictionary_ Can you hear me now? No, I need more computer paper. Listen, I’ll text you exactly what I need. Thanks, Luke. Talk to you later Dictionary_ How’s it going?</td></tr></table><div class="break"><br></div></div><div data-gr-conv-event="5" data-gr-conv-event-ms="1602135415343" data-gr-conv-user="[email protected]"><table class="event"><tr><td><span class="timeStamp">( <span data-gr-epochtime-ms="1602135415343">2020-10-08 05:36:55 AM GMT</span>"""

output= adam Dictionary_ Can you hear me now? No, I need more computer paper. Listen, I’ll text you exactly what I need. Thanks, Mike. Talk to you later Dictionary_ How’s it going?

What I've tried so far,:

from bs4 import BeautifulSoup
soup = BeautifulSoup(string)
print (soup.find('span',{'class':'buddy'}).text)

adam

Upvotes: 0

Views: 195

Answers (1)

boyenec
boyenec

Reputation: 1617

string_1 = soup.find('span',{'class':'buddyName0'}).text
string_2 = soup.find('tr').text

 print(str1+str2)

>>> print(str1+str2)

enter image description here

Upvotes: 0

Related Questions