0
我使用下面提到的代碼來獲取特定標籤的內容,但是當我嘗試執行它時,我收到了一些額外的數據,但我不明白爲什麼會發生。可以說,如果我搜索標題標籤,那麼我得到" [echo] Title : <title>Unit Test Results</title>,Unit Test Results"
這個結果,但問題是標題只包含"<title>Unit Test Results</title>"
爲什麼這個額外的",Unit Test Results"
事情來了。在螞蟻中使用js在HTML中使用標籤搜索
<project name="extractElement" default="test">
<!--Extract element from html file-->
<scriptdef name="findelement" language="javascript">
<attribute name="tag" />
<attribute name="file" />
<attribute name="property" />
<![CDATA[
var tag = attributes.get("tag");
var file = attributes.get("file");
var regex = "<" + tag + "[^>]*>(.*?)</" + tag + ">";
var patt = new RegExp(regex,"g");
project.setProperty(attributes.get("property"), patt.exec(file));
]]>
</scriptdef>
<!--Only available target...-->
<target name="test">
<loadfile srcFile="E:\backup\latest report\Report-20160523_2036.html" property="html.file"/>
<findelement tag="title" file="${html.file}" property="element"/>
<echo message="Title : ${element}"/>
</target>