【发布时间】:2017-04-27 09:57:56
【问题描述】:
我有一张这样的桌子:
protocol packets bytes bytes/pkt
------------------------------------------------------------------------
total 78913220 (100.00%) 47623614577 (100.00%) 603.49
ip 76930821 ( 97.49%) 45706321977 ( 95.97%) 594.12
tcp 45432316 ( 57.57%) 38990240707 ( 81.87%) 858.20
实际上,您可以在WIDE MAWI WorkingGroup 中找到一些示例。
我使用简单的 Python 代码获取数据,然后我想将每个项目存储在某个结构中,例如 dict。
例如:
这不是一个实用的代码!这是我需要的示例代码。
import httplib2
from BeautifulSoup import BeautifulSoup, SoupStrainer
import pandas as pd
http = httplib2.Http()
status, response = http.request('http://mawi.wide.ad.jp/mawi/ditl/ditl2017/201704131545.html')
for item in BeautifulSoup(response, parseOnlyThese=SoupStrainer('pre')):
res = item.text
pd.read_somefunction_to_read_string(res)
if pd['protocol']['ip'] > .09 * pd['protocol']['total']
do_something
预期输出:
[
{'protocol' : 'total', 'packet' : 78913220, 'bytes' : 47623614577},
{'protocol' : 'ip', 'packet' : 76930821, 'bytes' : 45706321977}
]
【问题讨论】:
标签: python python-2.7 pandas beautifulsoup