2
我有這樣的HTML代碼中,這樣做就可以了XPath的:PHP的XPath,無法檢索標籤後的文本有針對性的標籤
<b>Random Field:</b>
<p>
A random field describes an <a href="/index.php?page=glossary&term_id=230">
experiment</a> with outcomes being functions of more than one continuous variable,
for example U(x,y,z), where x, y, and z are coordinates in space. Random field is
extension of the concept of <a href="/index.php?page=glossary&term_id=598">random
process</a> into the case of multivariate argument.
</p>
我想這拿<p>
標籤內的文本:
$dom = new DomDocument();
$dom->loadHtml($curl_scraped_page);
$xpath = new DomXPath($dom);
print $xpath->evaluate('string(//p[preceding::b]/text())');
但它只是給了我這個:
A random field describes an
我要的是:
A random field describes an ..(an so on until).. of multivariate argument.
所以我猜問題在於<a>
標籤。因爲每當我嘗試在同一圖案文檔上執行此操作時,都會在此<a>
標籤之前停止。 謝謝..
謝謝^^評估和查詢有什麼區別?項目(0)在那裏意味着什麼?謝謝.. – Safira
'evaluate()'會返回一個類型化結果(nodelist,string,integer等),如果可能的話,' - > query()'總是返回一個'DOMNodeList',' - > item(0)從該列表中獲得第一個(0索引的)項目,在這種情況下是唯一的(第一個)'
'元素。如果您希望捕獲_more_''節點,您可以循環訪問DOMNodelist,以便''query()'返回&連接'手動'處的項目的' - > textContent'。 – Wrikken