木偶找到svg使用xlink:href

时间:2020-09-28 11:26:49

标签: html xml svg xpath puppeteer

我有以下html:

<use xlink:href

现在/logo可以是/logo-filled//*[name()='use'][contains(@*='logo')]

如何在Puppeteer中编写xpath表达式以获取这些信息?

我已经尝试过了:

Unable to perform XPath operation. The prefix "xlink" for attribute "xlink:href" associated with an element type "use" is not bound.

但是当我测试它时,我得到了错误:

$_POST = [
  'product_id' => 1,
  'quantity' => 9
]

1 个答案:

答案 0 :(得分:1)

更改

//*[name()='use'][contains(@*='logo')]
                             ^

//*[name()='use'][contains(@*,'logo')]
                             ^

//use[starts-with(@*,'/logo')]

但关于名称空间,另请参见How does XPath deal with XML namespaces?