find and find_all : odd behavior with string arg when name=None, recursive=False

Bug #1698990 reported by Thomas Proctor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Beautiful Soup
Invalid
Undecided
Unassigned

Bug Description

The attached file contains an example of the bug. When using a string/text match with the `string` or `text` arguments for `find` and `find_all`, no matches will be returned if `name=None` and `recursive=False`.

See Bug example for an example.

Revision history for this message
Thomas Proctor (theproctonator) wrote :
description: updated
Revision history for this message
Leonard Richardson (leonardr) wrote :

Thanks for filing this report. The behavior you're seeing is by design. Your third search is no less specific than the first, but it's searching for a different thing.

Passing 'tag' and 'string' into a find() method makes it look for a tag whose .string value is that tag. Passing 'string' but not 'tag' makes it look for a string, not a tag.

Taking out the recursive=False in your example will illustrate this.

>>> print(head.find(string=regex))
The Dormouse's story

With recursive=True in place, no matching string is found. The string is in the document, and removing recursive=True allows find() to find it.

This is covered in the documentation for the string argument (https://www.crummy.com/software/BeautifulSoup/bs4/doc/#id12)

Changed in beautifulsoup:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.