Python regular expression for HTML parsing (BeautifulSoup)

前端 未结 7 2099
感情败类
感情败类 2020-11-27 19:21

I want to grab the value of a hidden input field in HTML.


I

相关标签:
7条回答
  • 2020-11-27 20:00

    I agree with Vinko BeautifulSoup is the way to go. However I suggest using fooId['value'] to get the attribute rather than relying on value being the third attribute.

    from BeautifulSoup import BeautifulSoup
    #Or retrieve it from the web, etc.
    html_data = open('/yourwebsite/page.html','r').read()
    #Create the soup object from the HTML data
    soup = BeautifulSoup(html_data)
    fooId = soup.find('input',name='fooId',type='hidden') #Find the proper tag
    value = fooId['value'] #The value attribute
    
    0 讨论(0)
提交回复
热议问题