I'm using Pypeteer to screen scrape a page and I have the following code which selects various elements.
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]
What I would like to do, is to get the values of the various document.querySelector attributes (name, balance, liabilities) into those three python variables to then process them further down in the script.
The above code throws the following error:
pyppeteer.errors.ElementHandleError: Evaluation failed: SyntaxError: Illegal return statement
Not sure how to progress from this point. Any suggestions?
You need to use []
in javascript:
return [name, balance, liabilities]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.