返回顶部

收藏

Python 解析 html

更多
# 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)

标签:python

收藏

0人收藏

支持

0

反对

0

发表评论