python BeautifulSoup find all input for specific form
11,599
As noted in comments, chain find
and find_all()
for the context-specific search:
form = soup.find('form')
inputs = form.find_all('input')
If you want direct input
elements only, add recursive=False
:
form.find_all('input', recursive=False)
Or, using CSS selectors:
soup.select("form input")
And, getting direct input
child elements only:
soup.select("form > input")
Author by
user1220022
Updated on June 24, 2022Comments
-
user1220022 almost 2 years
I'm trying to use
BeautifulSoup
to extract input fields for a specific form only.Extracting the form using the following:
soup.find('form')
Now I want to extract all input fields which are a child to that form only.
How can I do that with BS?