从页面返回值给python.在Pyppeteer (Python Puppeteer)中评估



我正在使用Pypeteer屏幕抓取页面,我有以下代码选择各种元素。

foo = await page.evaluate("""
var name = document.querySelectorAll("h2")[0].innerText
var balance = document.querySelectorAll("h3")[0].outerText
var liabilities = document.querySelectorAll("h3")[1].outerText
return name,balance,liabilities

""")
name = foo[0]
balance = foo[1]
liabilities = foo[2]

我要做的是获取各个文档的值。querySelector属性(名称、余额、负债)放入这三个python变量中,然后在脚本中进一步处理它们。

以上代码抛出以下错误:

pyppeteer.errors.ElementHandleError: Evaluation failed: SyntaxError: Illegal return statement

不知道如何从这一点前进。有什么建议吗?

你需要在javascript中使用[]:

return [name, balance, liabilities]