Python 解析 html

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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