find and find_all : odd behavior with string arg when name=None, recursive=False
Bug #1698990 reported by
Thomas Proctor
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.
description: | updated |
To post a comment you must log in.
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)