Python 解析 html

2014-11-17 0 526
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 Python 解析 html http://www.ox520.com/14904.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务