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?
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")
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With