【求助】bs4--如何将表格内容放入dict?
python吧
全部回复
仅看楼主
level 6
woohaha 楼主
我有一个表格,内容如下:
html = '<table bgcolor="#CCCCCC" border="0" cellpadding="6" cel
lsp
acing="1" width="100%">
<tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff';" onmouseover="this.style.backgroundColor='#ffcc00';">
<th></th>
<th>代理</th>
<th>端口</th>
<th>国家</th>
</tr>
<tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff';" onmouseover="this.style.backgroundColor='#ffcc00';">
<td width="30">1</td>
<td>118-163-44-224.hinet-ip.hinet.net</td>
<td width="60">3128</td>
<td width="60">TW</td>
</tr>
<tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff';" onmouseover="this.style.backgroundColor='#ffcc00';">
<td width="30">2</td>
<td>124.195.8.65</td>
<td width="60">8080</td>
<td width="60">ID</td>
</tr>
<tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff';" onmouseover="this.style.backgroundColor='#ffcc00';">
<td width="30">3</td>
<td>110.77.250.190</td>
<td width="60">8080</td>
<td width="60">TH</td>
</tr>
</table>'
我想用bs4处理,将表格的内容以输出成一个dict,格式如下
data = {'server':['118-163-44-224.hinet-ip.hinet.net','124.195.8.65','110.77.250.190'],'port':['3128','8080','8080'],'location':['TW','ID','TH']}
我试来试去都只能得到一个list,求敎。
2013年07月03日 08点07分 1
level 13
你的代码?
2013年07月03日 10点07分 2
回复 woohaha :全乱了,我还是截图吧
2013年07月03日 12点07分
level 11
还是需要经常处理的 http://paste.ubuntu.com/5839993/
2013年07月03日 11点07分 3
谢谢你的代码,我要消化一下[哈哈]
2013年07月03日 12点07分
level 6
woohaha 楼主
2013年07月03日 12点07分 4
1