用于HTML解析的Python正则表达式(BeautifulSoup)

用于HTML解析的Python正则表达式(BeautifulSoup),第1张

用于HTML解析的Python正则表达式(BeautifulSoup)

对于这种特殊情况,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']


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5643668.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存