Searcher512
Searcher512

Reputation: 11

Cannot detect string is Soup output

I need to detect whether a specific String exists within a Soup output. This string is in the soup output

This day is not yet available for booking or viewing of tee times.

but no matter what code I write, (i have used an IN test, I have tried single quotes)I can never get any out put but 'None' even though the line is clearly in the soup output.

I have included part of a very large soup output.

I have included a part of my python code.

Will someone tell me what is wrong?

Soup partial:

<div class="tabular_cell member_sheet_right"><a class="pageHelpHeader inactive"
href="#"><span>Instructions</span></a><div class="sub_instructions pageHelp" dat
a-fthelptitle="Instructions"><h2 class="altTitle">Instructions:</h2><p><b>Note:<
/b> This date is not yet available for members to make tee times or view the tee
 sheet.</p></div></div>
<div class="clearFix"></div>
</div>
</div>
<div class="rwdCourseDate"><div class="rwdDateSelect"><label><b>Date:</b><span>W
ednesday</span><input class="ft_date_picker_field calendar member ftMemberSheetC
alendar hasDatepicker" data-ftdefaultdate="6/23/2021" disabled="" id="dp16238484
01067" readonly="readonly" type="text" value="6/23/2021"/></label></div></div><d
iv class="tee_sheet_color_legend">
<p class="color_legend">
<span class="color_legend_item color_legend_restriction" style="background-color
:Lightpink; color:#000000">2021 Ladies Day May Sep</span><span class="color_lege
nd_item color_legend_restriction" style="background-color:Yellow; color:#000000"
>Ladies Niners May Jul</span>
</p><p>
</p></div>
<div class="notice_block sub_instructions">
<h2>Notice:</h2>
<p>This day is not yet available for booking or viewing of tee times.</p>
<p>Please use the calendars above to select a different day's tee sheet or to re
load this day's tee sheet.</p>
</div>
</div><div id="footer"><span><span>Copyright c 2021 ForeTees, LLC.</span><span>
</span><span>All rights reserved.</span></span></div></div></div><div class="ui-
datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all calendar
" id="ui-datepicker-div"></div></body><a href="javascript:void(0);" id="scrollUp
" style="display: none;"></a></html>
End of list soup
test None
ERROR: NO AVAILABLE TEE TIMES

Starting a new day
Thu blockTime '06:00:00'
set_alarm_timer =  05:50:00
Starting a New Alarm, set_alarm_timer =  05:50:00

Code:

   get_source = driver.page_source  
   soup = BeautifulSoup(get_source, 'html.parser')
   print(soup)
  
   print("End of list soup")
   testsoup = soup.find("p", string ="This day is not yet available for booking or viewing of of tee times")
   print("test",testsoup)

Upvotes: 1

Views: 38

Answers (1)

MendelG
MendelG

Reputation: 20088

The string= parameter is expecting an exact match, you must specify the entire string to be matched, you only passed some of the text, missing a dot . at the end. Also, you and an extra word "of" in the text.

Try the following instead, passing the full string to be matched:

testsoup = soup.find("p", text="This day is not yet available for booking or viewing of tee times.")

An alternative would be to pass a lambda function into find()instead, which wouldn't require specifying the entire text to be matched:

print(
    soup.find(
        lambda t: t.name == "p"
        and "This day is not yet available for booking" in t.text
    )
)

Output (in both examples):

<p>This day is not yet available for booking or viewing of tee times.</p>

Upvotes: 1

Related Questions