<p>简单方法,只需添加如何管理数据:</p>
<pre><code>from bs4 import BeautifulSoup
html_doc = """
<div class="postcodedata">
<b>Latitude:</b> 51.19 degrees<br>
<b>Longitude:</b> 0.07 degrees<br>
<b>Postcode Town:</b> Tonbridge<br>
<b>Easting:</b> 545102 degrees<br>
<b>Northing:</b> 145533 degrees<br>
<b>Grid Ref:</b> TQ451455<br>
<b>District:</b> Sevenoaks<br>
<b>Ward:</b> Edenbridge South and West<br>
<b>Satnav:</b> TN8<br>
<b><a href="phonecodes/"><u>STD Phone Code</u></a>:</b>
(01959) xxxxxx
<div class="clear"></div>
</div>
"""
soup = BeautifulSoup(html_doc,'html.parser')
data = soup.find(attrs={'class' : 'postcodedata'})
#split line by line
values = data.text.split('\n');
for i in range(len(values)):
#for each line split by semicolon so line[0] has the key and line[1] has the value
line = values[i].split(':')
#check the required key
if line[0]=='Postcode Town' or line[0]=='Satnav' or line[0] =='STD Phone Code':
print line[1]
</code></pre>
<p>希望帮助了你!在</p>