如何在python中废弃元素值中的t \值

问题描述 投票:-1回答:1

我到处搜索,但找不到答案。

我需要获取元素值内的内容,例如我需要从下面获取值(Xerox WorkCentre 7220),请帮忙。

<input id="ni.VEe17e1924dbe4e7400d17a5ca0b961966_read_only" name="ni.VEe17e1924dbe4e7400d17a5ca0b961966_read_only" class="cat_item_option sc-content-pad form-control" value="Xerox WorkCentre 7220" readonly="true">
python html beautifulsoup scraper
1个回答
1
投票
from bs4 import BeautifulSoup

soup=BeautifulSoup(html,'html.parser')
html='''<input id="ni.VEe17e1924dbe4e7400d17a5ca0b961966_read_only" name="ni.VEe17e1924dbe4e7400d17a5ca0b961966_read_only" class="cat_item_option sc-content-pad form-control" value="Xerox WorkCentre 7220" readonly="true">'''

input_tag = soup.find('input')
print(input_tag['value'])

Output

'Xerox WorkCentre 7220'

© www.soinside.com 2019 - 2024. All rights reserved.