【问题标题】:How can you scrape the t\value inside the element value in python如何在 python 中刮取元素值内的 t\value
【发布时间】:2018-09-12 07:00:38
【问题描述】:

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

我需要获取 elemant 值中的内容,例如我需要从下面获取值(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 web-scraping beautifulsoup


【解决方案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'])

输出

'施乐工作中心 7220'

【讨论】:

  • res = requests.get("sadara.service-now.com/…) res1 = res.text soup = BeautifulSoup(res1,'html.parser') input_tag = soup.find("input",{"class" :"form-control disabled"}) print(input_tag) 当我尝试这个时它说 print(input_tag['value']) TypeError: 'NoneType' object is not subscriptable
  • 您要废弃的站点中没有 form-control disabled
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-21
  • 2020-08-29
  • 1970-01-01
  • 2018-06-16
  • 2021-07-06
相关资源
最近更新 更多