- # coding=utf-8
- import requests
- import lxml
- from lxml import html
- r = requests.get("http://172.16.1.132:10022")
- doc = html.document_fromstring(r.content)
- table = doc.xpath('/html/body/table')[0]
- informs = table.findall('tr/td/font')
- vminfo = "vm_name, vm_mac, vm_state, vm_heart, eng_version, end_db_date, count".split(", ")
- texts = [item.text for item in informs]
- loops = loop = len(informs)/7
- vms = []
- for i in range(loop):
- d = {}
- for j in range(7):
- print(vminfo[j])
- d[ vminfo[j] ] = texts[ i*7 +j]
- print( d )
- vms.append(d)
- for i in vms:
- print(i)
- #该片段来自于http://www.codesnippet.cn/detail/1501201511545.html
来源: http://www.codesnippet.cn/detail/1501201511545.html