gpt4 book ai didi

javascript - 如何使用我的 Node js 程序中任何元素的值?

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:05 26 4
gpt4 key购买 nike

Element (<input id="pagenum-input" class="form-control" aria-label="..." value="1" min="1" max="28">)

我想使用 max(28) 的值作为我在第二个循环中创建的变量最大值的值。我如何从输入标签获取最大值到我的程序?任何帮助,将不胜感激。谢谢!

const puppeteer = require('puppeteer');

async function getPic() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();

for (let j=2; j<=6; j++) {
await page.setViewport({width: 2000, height: 2500})
await page.goto('http://epaper.freepressjournal.in/');
await page.click('body > div > div.common_section > div > div > div.rw_rightcrousel > div > div:nth-child('+j+') > a > div > img');
await page.waitFor(2000);
await page.click('#left-chunk-1 > img');
var maximum;
for (let i= 1; i<=maximum; i++) {
await page.waitFor(2000);
await page.screenshot({path: '//192.168.2.19/em/automatic downloading/Puppeteer/freepressjournal/'+j+''+i+'.png'});
await page.waitFor(2000);
await page.click('#page-div > a.right_arrow_pgright.btn_next');
}
}

await browser.close();
}

getPic();

// This loop will automatically get the value of max that is 28.
// The value of max will vary according to pages. The program should accept
// the value of max in maximum and run the loop accordingly.
for (let i= 1; i<=maximum; i++)

最佳答案

借助 page.evaluate 函数,您可以与页面上的任何元素进行交互。以下是如何找到感兴趣的输入元素并访问其属性之一:

var maximum = await page.evaluate(() => {
return document.getElementById("pagenum-input").getAttribute("max");
});

关于javascript - 如何使用我的 Node js 程序中任何元素的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56373466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com