Find value of input field in html doc using python

后端 未结 2 950
青春惊慌失措
青春惊慌失措 2021-01-19 18:53

I am trying to get input values from an HTML doc and want to parse out the values of hidden input fields. For example how can I parse out only the value from the snippet bel

2条回答
  •  花落未央
    2021-01-19 19:27

    You could use BeautifulSoup:

    >>> htmlstr = """    
    ...     """
    >>> from BeautifulSoup import BeautifulSoup
    >>> soup = BeautifulSoup(htmlstr)
    >>> [(n['name'], n['value']) for n in soup.findAll('input')]
    [(u'post_form_id', u'd619a1eb3becdc05a3ebea530396782f'), (u'fb_dtsg', u'AQCYsohu')]
    

提交回复
热议问题