Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多姆。从选项标记中的给定文本获取值属性_Php_Dom_Xpath_Css Selectors_Goutte - Fatal编程技术网

Php 多姆。从选项标记中的给定文本获取值属性

Php 多姆。从选项标记中的给定文本获取值属性,php,dom,xpath,css-selectors,goutte,Php,Dom,Xpath,Css Selectors,Goutte,我试图通过CSS选择器或xpath表达式从给定的文本中获取值,但我不知道是否可以执行此操作。 这是我的HTML: <select name="product" style="width: 430px"> <option value="0" selected="selected"></option> <option value="3181">389-ds-base</option> <option value="3511">

我试图通过CSS选择器或xpath表达式从给定的文本中获取值,但我不知道是否可以执行此操作。 这是我的HTML:

 <select name="product" style="width: 430px">
<option value="0" selected="selected"></option>
<option value="3181">389-ds-base</option>
<option value="3511">7-Zip</option>
我不想把数字3511作为参数传递,而是传递文本


希望我能说清楚,谢谢大家。

xpath表达式
字符串(//option[.=“7-Zip”]/@value)
将找到任何文本内容等于“7-Zip”的
元素,并将其值属性作为字符串返回。

xpath表达式
字符串(//option[.=“7-Zip”]/@value)
将查找文本内容等于“7-Zip”的任何
元素,并将其值属性作为字符串返回。

xpath表达式
字符串(//option[.=“7-Zip”]/@value)
将查找文本内容等于“7-Zip”的任何
元素并将其值属性作为字符串返回。

xpath表达式
字符串(//option[.=“7-Zip”]/@value)
将查找文本内容等于“7-Zip”的任何
元素,并将其值属性作为字符串返回。

引用:

  • 首先,我想让您了解一个事实,即DomCrawler::filter()和DomCrawler::filterXPath()方法是围绕DomCrawler::filterRelativeXPath()私有方法的包装器

    浏览一下filter()和filterXPath()方法的API引用,您会发现它们都将返回一个DOMClawler实例;可以从filterRelativeXPath()方法中查看。filterRelativeXPath()方法反过来使用PHP的XPath::query()方法

    Paul提供的XPath表达式虽然在技术上是正确的,但在Symfony DomCrawler的上下文中不适用。事实上,如果你要做:

    $value = $crawler->filterXPath('string(//option[.="7-Zip"]/@value)');
    
    您可能会从DOMXPath::query()中得到错误或警告

    使用Symfony DomCrawler组件时,必须执行以下操作:

    $value = $crawler->filterXPath('//option[.="7-Zip"]/') // get the node
                     ->extract(['value'])[0];              // extract the value attribute and then associate the first element of the resulting array to $value
    
    参考资料:

  • 首先,我想让您了解一个事实,即DomCrawler::filter()和DomCrawler::filterXPath()方法是围绕DomCrawler::filterRelativeXPath()私有方法的包装器

    浏览一下filter()和filterXPath()方法的API引用,您会发现它们都将返回一个DOMClawler实例;可以从filterRelativeXPath()方法中查看。filterRelativeXPath()方法反过来使用PHP的XPath::query()方法

    Paul提供的XPath表达式虽然在技术上是正确的,但在Symfony DomCrawler的上下文中不适用。事实上,如果你要做:

    $value = $crawler->filterXPath('string(//option[.="7-Zip"]/@value)');
    
    您可能会从DOMXPath::query()中得到错误或警告

    使用Symfony DomCrawler组件时,必须执行以下操作:

    $value = $crawler->filterXPath('//option[.="7-Zip"]/') // get the node
                     ->extract(['value'])[0];              // extract the value attribute and then associate the first element of the resulting array to $value
    
    参考资料:

  • 首先,我想让您了解一个事实,即DomCrawler::filter()和DomCrawler::filterXPath()方法是围绕DomCrawler::filterRelativeXPath()私有方法的包装器

    浏览一下filter()和filterXPath()方法的API引用,您会发现它们都将返回一个DOMClawler实例;可以从filterRelativeXPath()方法中查看。filterRelativeXPath()方法反过来使用PHP的XPath::query()方法

    Paul提供的XPath表达式虽然在技术上是正确的,但在Symfony DomCrawler的上下文中不适用。事实上,如果你要做:

    $value = $crawler->filterXPath('string(//option[.="7-Zip"]/@value)');
    
    您可能会从DOMXPath::query()中得到错误或警告

    使用Symfony DomCrawler组件时,必须执行以下操作:

    $value = $crawler->filterXPath('//option[.="7-Zip"]/') // get the node
                     ->extract(['value'])[0];              // extract the value attribute and then associate the first element of the resulting array to $value
    
    参考资料:

  • 首先,我想让您了解一个事实,即DomCrawler::filter()和DomCrawler::filterXPath()方法是围绕DomCrawler::filterRelativeXPath()私有方法的包装器

    浏览一下filter()和filterXPath()方法的API引用,您会发现它们都将返回一个DOMClawler实例;可以从filterRelativeXPath()方法中查看。filterRelativeXPath()方法反过来使用PHP的XPath::query()方法

    Paul提供的XPath表达式虽然在技术上是正确的,但在Symfony DomCrawler的上下文中不适用。事实上,如果你要做:

    $value = $crawler->filterXPath('string(//option[.="7-Zip"]/@value)');
    
    您可能会从DOMXPath::query()中得到错误或警告

    使用Symfony DomCrawler组件时,必须执行以下操作:

    $value = $crawler->filterXPath('//option[.="7-Zip"]/') // get the node
                     ->extract(['value'])[0];              // extract the value attribute and then associate the first element of the resulting array to $value
    

    您是指字符串作为PHP函数接收xpath
    //选项[.=“7-Zip”]/@value
    作为参数吗?您是指字符串作为PHP函数接收xpath
    //选项[.=“7-Zip”]/@value
    作为参数吗?您是指字符串作为PHP函数接收xpath
    //选项[.=“7-Zip”]/@value
    作为参数?您的意思是字符串作为PHP函数,它接收xpath
    //选项[.=“7-Zip”]/@value
    作为参数?