Lolak
Lolak

Reputation: 317

getting multi value from hidden form with beautifullSoup

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

Answers (1)

MePsyDuck
MePsyDuck

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

Related Questions