How To Get The Hidden Input's Value By Using Python?
How can i get input value from html page like I have input name [ name='captId' ]
Solution 1:
Using re
module to parse xml or html is generally considered as bad practice. Use it only if you are responsable for the page you try to parse. If not, either your regexes are awfully complex, or your script could break if someone replaces <input type="hidden" name=.../>
with <input name="..." type="hidden" .../>
or almost anything else.
BeautifulSoup is a html parser that :
- automatically fixes minor errors (unclosed tags ...)
- build a DOM tree
- allows you to browse the tree, search for specific tags, with specific attributes
- is useable with Python 2 and 3
Unless you have good reasons not to do it, you should use it rather than re
for HTML parsing.
For example assuming that txt
contains the whole page, find all hidden fields would be as simple as :
from bs4 import BeautifulSoup
soup = BeautifulSoup(txt)
hidden_tags = soup.find_all("input", type="hidden")
for tag in hidden_tags:
# tag.name is the name and tag.value the value, simple isn't it ?
Post a Comment for "How To Get The Hidden Input's Value By Using Python?"