我正在尝试解析许多不同页面的 HTML 源代码,例如:
http://www.ielts.org//test_centre_search/results.aspx?TestCentreID=dd50346f-60bc-4a4f-a37f-7e3d34df0bf8 或 www.ielts.org//test_centre_search/results.aspx?TestCentreID=feb563e3-43db-4d40- a6b1-223e2fb7191b(我有800页这样的)
它们都采用相同的格式。我正在尝试解析“测试费”值。
<TABLE style="BORDER-RIGHT: buttonshadow 1px solid; BORDER-TOP: buttonhighlight 1px solid; FONT: messagebox; BORDER-LEFT: buttonhighlight 1px solid; COLOR: buttontext; BORDER-BOTTOM: buttonshadow 1px solid; BACKGROUND-COLOR: buttonface" cellSpacing=0 cellPadding=4 width=500>
<TBODY></TBODY></TABLE><table id="Template_ctl21_TestCentreView1_TestCentreTable" Width="400" border="0">
<tr>
<td><img src="https://www.ielts.org/TestCentreLogos/TestCentre/dd50346f-60bc-4a4f-a37f-7e3d34df0bf8.jpg" align="right" style="border-width:0px;" /><span class="TestCentreViewTitle">University of Canberra Test Centre</span><BR><BR><span class="TestCentreViewLabel">Address:</span><BR><span class="TestCentreViewBody">IELTS Administrator</span><BR><span class="TestCentreViewBody">Building 16</span><BR><span class="TestCentreViewBody">Wilpena Street, Bruce</span><BR><span class="TestCentreViewBody">ACT - Canberra</span><BR><span class="TestCentreViewBody">2617</span><BR><BR><span class="TestCentreViewLabel">Tel: </span><span class="TestCentreViewBody">61 2 6201 2669</span><BR><span class="TestCentreViewLabel">Fax: </span><span class="TestCentreViewBody">61 2 6201 5089</span><BR><span class="TestCentreViewLabel">Email: </span><a class="TestCentreViewLink" href="mailto:ielts@canberra.edu.au">ielts@canberra.edu.au</a><BR><span class="TestCentreViewLabel">Web: </span><a class="TestCentreViewLink" href="http://www.canberra.edu.au/uceli/ielts">http://www.canberra.edu.au/uceli/ielts</a><BR><BR>**<span class="TestCentreViewLabel">Test Fee: </span><span class="TestCentreViewBody">AUD$330</span>**<BR><BR><div style="overflow-y:scroll;overflow-x:visible;height:250px;;"><table cellspacing="0" cellpadding="2" border="0" style="border-collapse:collapse;">
<tr>
</table></div><BR><span class="TestCentreViewBody"><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT size=3><FONT color=#000000><FONT face=Calibri>The IELTS office now closes at 4:00pm on Friday afternoons.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P> </P></span><BR></td>
</tr>
</table>
以上是我们感兴趣的部分来源。我要解析的是:
**<span class="TestCentreViewLabel">Test Fee: </span><span class="TestCentreViewBody">AUD$330</span>**
问题是我们有很多不同<span>
的同一个类(TestCentreViewBody)和一个你有5个页面,其他8个等等......所以我不知道如何隔离这个?
我正在寻找一种方法来隔离这个值。
PS:我注意到<span>
最后一个之前的似乎总是包含我正在寻找的值。所以我试图做的是:
LOL = findAll('span' .. with the 'class' : 'TestCentreViewBody')
Value = LOL[len(lol)-1]
但这似乎不起作用。