当我在代码中运行它时,它说dottt是未定义的,但是为什么它正确地吸收了pdfcitystatezipselector。如果我将dottt替换为字符串文字,则效果很好。
const pdfcitystatezipselector = 'body > div:nth-child(1) > div:nth-child(6) > span';
const dottt = "111111";
await page.$eval(pdfdotselector, (element1, dotttt) => {
element1.innerHTML = dottt;
});
请不要删除此帖子。我看到其他类似的帖子。但看不到有什么方法可以解决我的问题。他们相信他们会更多地使用page.evaluate,而不是page.eval。
您需要将dotttt
参数传递给$eval
函数:
const pdfcitystatezipselector = 'body > div:nth-child(1) > div:nth-child(6) > span';
const dottt = "111111";
await page.$eval(pdfdotselector,
(element1, dotttt) => {
element1.innerHTML = dottt;
},
dotttt); // here