我在网站上有一张桌子,我想用class ='col-sm-1 available-day'抓取所有tds 我使用puppeteer进行了如下尝试:
let result = await page.evaluate(() => {
return Array.from(document.querySelectorAll('td.col-sm-1.available-day'));
});
但是当我尝试输出未定义的结果时,有什么帮助吗?
答案 0 :(得分:2)
这是预期的行为。 {
"name": "ontheroadagain",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"dev": "webpack-dev-server --mode development",
"prod": "webpack --mode production",
"test": "eslint --fix *.js",
"fix": "eslint --fix *.js",
"build": "webpack --config webpack.config.dev.js -w"
},
"repository": {
"type": "git",
"url": "an actual url is here"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "an actual url is here"
},
"homepage": "an actual url is here",
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"babel-loader": "^8.1.0",
"css-loader": "^4.3.0",
"eslint": "^7.10.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.1",
"html-webpack-plugin": "^4.5.0",
"husky": "^4.3.0",
"vue-loader": "^15.9.3",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.6.12",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"express": "^4.17.1",
"mysql2": "^2.2.5",
"sequelize": "^6.3.5",
"vue": "^2.6.12",
"vue-router": "^3.4.5"
},
"husky": {
"hooks": {
"pre-commit": "npm run fix",
"pre-push": "npm run fix",
"...": "..."
}
}
}
获取DOM节点,这些节点是无法从document.querySelectorAll
返回的复杂对象。
您需要返回可以序列化的简单对象,例如,在这里,我们返回所选元素的文本值数组:
page.evaluate