对于这种特殊情况,BeautifulSoup比正则表达式更难编写,但是它更健壮…我只是为BeautifulSoup示例提供帮助,因为您已经知道要使用哪个正则表达式:-)
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 datasoup = BeautifulSoup(html_data)fooId = soup.find('input',name='fooId',type='hidden') #Find the proper tagvalue = fooId.attrs[2][1] #The value of the third attribute of the desired tag #or index it directly via fooId['value']


