Available 4/1 at 9:00 AM I am trying to extract text from the html div above using the code below date = p" /> Available 4/1 at 9:00 AM I am trying to extract text from the html div above using the code below date = p" /> Available 4/1 at 9:00 AM I am trying to extract text from the html div above using the code below date = p"/>

extracting text from html div tag using python and bs4

231 Views Asked by At
<div class="available-date-component">Available 4/1 at 9:00 AM</div>

I am trying to extract text from the html div above using the code below

date = page.find('div', {'class' : 'available-date-component'}) 
print(date.string) # this line needs to be fixed

Does anyone have any suggestsions on how I can only print 'Available 4/1 at 9:00 AM' isntead of the entire div?

1

There are 1 best solutions below

0
evangandy9600 On
def clean(raw_html):
    cleaner = re.compile('<.*?>')
    cleantext = re.sub(cleaner, '', raw_html)
    return cleantext

I ended up passing the html div through this function that removes all of the tags and leaves the text that I wanted.