Reputation: 317
i am trying to get all values from hidden form input
but it return only the first value
this is what i am using
from bs4 import BeautifulSoup
s = """<form id="test" action="#" method="post">
<input name="1" type="hidden" value="test1">
</form>
<form id="test" action="#" method="post">
<input name="1" type="hidden" value="test2">
</form>
"""
soup = BeautifulSoup(s, "html.parser")
form = soup.find("form", {"id": "test"})
print( form.input.attrs['value'] )
have tried to use find_all instead but not working
Upvotes: 0
Views: 26
Reputation: 374
Strange, find_all
works for me.
from bs4 import BeautifulSoup
s = """
<form id="test" action="#" method="post">
<input name="1" type="hidden" value="test1">
</form>
<form id="test" action="#" method="post">
<input name="1" type="hidden" value="test2">
</form>
"""
soup = BeautifulSoup(s, "html.parser")
forms = soup.find_all("form", {"id": "test"})
for form in forms:
print(form.input.attrs['value'])
Results in:
test1
test2
Upvotes: 2