每次我将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));
答案 0 :(得分:1)
由于它不是有效的XPath,请考虑以下XPath:
//table/tbody/tr/td[1]
或者如果您需要依靠class
名称:
//table[@class = 'classname']/tbody/tr/td[1]