如何按名称获取select标记的php-DOMDocument xpath


How to get php DOMDocument xpath of a select tag by name

我有以下html:

<select type="text" name="City" value="">
<option>city1</option>
<option>city2</option>
<option>city3</option>

我正在尝试使用DOMDocument的xpath来获取城市的数组。到目前为止,我的xpath表达式是:

$xpath = new DOMXPath($dom);
$nodeList = $xpath->query("//select[name=='City']/option"); 

这不起作用,我不明白为什么。

票据

尝试

$nodeList = $xpath->query("//select[@name='City']/option");