人偶-字符串不是有效的XPath表达式

时间:2019-03-15 00:29:14

标签: xpath puppeteer

每次我将xpath传递给函数时,它都会返回string is not a valid XPath expression。为什么会这样?

const searchSelector = '//*table/tbody/tr/td[1]';

const result = await page.evaluate(element => {
      return element.textContent;
    }, await page.$x(searchSelector));

html

1 个答案:

答案 0 :(得分:1)

由于它不是有效的XPath,请考虑以下XPath:

//table/tbody/tr/td[1]

或者如果您需要依靠class名称:

//table[@class = 'classname']/tbody/tr/td[1]