使用mshtml解析,逻辑上容易理解,可以准确得到前一个。
http://www.autoitx.com/thread-44262-1-1.html
#include <IE.au3>
#include <MSHtml.au3> ;使用mshtml解析html
Local $html = _
'<SPAN class=member>系统消息说:</SPAN><SPAN class=time>2014-05-12 08:01:43</SPAN>' & @CRLF & _
'<DIV id=ext-gen1071 class=message-body>会话建立</DIV><SPAN class=servicer>客服A说:</SPAN><SPAN class=time>2014-05-12 08:01:50</SPAN>' & @CRLF & _
'<DIV id=ext-gen1072 class=message-body>您好</DIV><SPAN class=member>' & @CRLF & _
'</DIV><SPAN class=member>系统消息说:</SPAN><SPAN class=time>2014-05-12 08:06:55</SPAN>' & @CRLF & _
'<DIV id=ext-gen1079 class=message-body>会话建立</DIV><SPAN class=servicer>客服B说:'
Local $doc = _MHDocGetObj()
_MHDocWriteHTML($doc,$html) ;写入html源码
;解析
Local $spans = _IETagNameGetCollection($doc,"span") ;返回span集合
Local $num = @extended - 2 ;倒数第二个元素序号(元素个数 - 1 是最后一个元素序号)
Local $span = _IETagNameGetCollection($doc,"span",$num) ;得到对象
MsgBox(64,"成功提取",$span.outertext)
|