Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Puppeter的page.eval函数上未定义的变量_Javascript_Bots_Eval_Puppeteer_Headless - Fatal编程技术网

Javascript 使用Puppeter的page.eval函数上未定义的变量

Javascript 使用Puppeter的page.eval函数上未定义的变量,javascript,bots,eval,puppeteer,headless,Javascript,Bots,Eval,Puppeteer,Headless,当我在代码中运行它时,它表示dottt是未定义的,但是为什么它正确地接受了pdfcitystatezipselector。如果我用一个字符串文字替换dottt,它就工作得很好 const pdfcitystatezipselector = 'body > div:nth-child(1) > div:nth-child(6) > span'; const dottt = "111111"; await page.$eval(pdfdotselector, (eleme

当我在代码中运行它时,它表示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;
  });

您需要将
dottt
参数传递给
$eval
函数:

constpdfcitystatezipselector='body>div:n个孩子(1)>div:n个孩子(6)>span';
const dottt=“111111”;
等待页面$eval(pdfdotselector,
(元素1,dottt)=>{
element1.innerHTML=dottt;
},
dottt);//在这里

我假设
dottt
应该是
dottt
——否则我就完全搞不懂了。请注意,有两个单独的变量称为
dottt
。第一个被声明为
const dottt=“111111”。但是在函数的作用域中还有另一个(函数的参数),它覆盖了第一个。它是未定义的,可能是因为该函数仅使用一个参数调用。我只是尝试使用在函数内部的函数外部声明的变量。当我这样做时,它一直给我一个未定义的值。我尝试了你的精确代码,它仍然说“ReferenceError:dottt未定义”。我使用的代码如下。
constpdfdotselector='body>div:nth child(1)>div:nth child(2)>span';const dottt=“111111”;等待页面。$eval(pdfdotselector,(element1,dottt)=>{element1.innerHTML=dottt;},dottt)