Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文档里的某个xpath不起作用 #152

Open
kekeyumuku opened this issue May 25, 2020 · 3 comments
Open

文档里的某个xpath不起作用 #152

kekeyumuku opened this issue May 25, 2020 · 3 comments

Comments

@kekeyumuku
Copy link

kekeyumuku commented May 25, 2020

文档里的例子如下:

$html =<<<STR
    <div id="demo">
        <span class="tt">bbb</span>
        <span>ccc</span>
        <p rel="pnode">ddd</p>
    </div>
STR;

//获取id为demo的div内容
$data = selector::select($html, "//div[@id='demo']");

print_r($data),运行结果是:

 <span class="tt">bbb</span>
 <span>ccc</span>
  <p rel="pnode">ddd</p>

// 获取class为tt的span内容
$data = selector::select($html, "//div[@class='tt']");

print_r($data),运行结果是空的,啥都打印不出来

// 获取rel为pnode的p内容
$data = selector::select($html, "//div[@rel='pnode']");

print_r($data),运行结果是空的,啥都打印不出来

另外一个例子:

$html =<<<STR
    <td data-value="3.80">3.80</td>    
    <td data-value="3.80">3.80</td>    
    <td data-value="3.80">3.80</td>    
    <td data-value="3.80">3.80</td>    
STR;

// 获取 td 的 data-value 属性
$data = selector::select($html, "//td@data-value");

print_r($data),运行结果是空的,啥都打印不出来

为什么会这样呢,是php配置需要修改吗,还是其他什么原因呢?麻烦您能帮我解答一下吗,非常感谢。

@xjimmy906
Copy link

xjimmy906 commented Jun 11, 2020

$html =<<<STR
    <td data-value="3.80">3.80</td>    
    <td data-value="3.80">3.80</td>    
    <td data-value="3.80">3.80</td>    
    <td data-value="3.80">3.80</td>    
STR;

// 获取 td 的 data-value 属性
$data = selector::select($html, "//td@data-value");

这个打印selector::$error,显示的是xpath语法错误
@owner888 是森么问题导致的 ?这个xpath应该没写错啊

@xjimmy906
Copy link

// 获取 td 的 data-value 属性
文档的这个$data = selector::select($html, "//td@data-value");写法错误

正确写法为$data = selector::select($html, "//td/@data-value");

@kekeyumuku @owner888 @awebc

@owner888
Copy link
Owner

owner888 commented Jul 1, 2021

感谢支持,我去改过来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants