admin管理员组文章数量:1024054
i am using puppeteer to try to take a screenshot of a website but first i have to press a button called "Lifetime" its selector is:
#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected
i have to first scroll down press the lifetime button and take a screenshot of the "solo", "duo" and "squad" stats like this:
target photo:
i am trying this in non-headless mode to make sure it works but it doesnt seem to be working. i have got my code to the point where it will scroll down to the element but not click it using page.click(SELECTOR). so far i have been able to open the webpage and scroll down but when i try to use page.click it does not work. i will worry about the screenshot later once i can figure out how to press the "lifetime" button
my code is:
var puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.goto('.BadGuyBen');
await page.tap('#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected');
await page.waitFor(2000);
await page.screenshot({
path: 'stats.png',
fullPage: true
})
browser.close();
};
scrape();
EDIT: i will take a fullscreen screenshot of the page then use jimp module to crop it so mainly i have to figure out how to press the button
EDIT: im an idiot i was using the wrong selector my bad :)
i am using puppeteer to try to take a screenshot of a website but first i have to press a button called "Lifetime" its selector is:
#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected
i have to first scroll down press the lifetime button and take a screenshot of the "solo", "duo" and "squad" stats like this:
target photo:
i am trying this in non-headless mode to make sure it works but it doesnt seem to be working. i have got my code to the point where it will scroll down to the element but not click it using page.click(SELECTOR). so far i have been able to open the webpage and scroll down but when i try to use page.click it does not work. i will worry about the screenshot later once i can figure out how to press the "lifetime" button
my code is:
var puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.goto('https://fortnitetracker./profile/pc/Twitch.BadGuyBen');
await page.tap('#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected');
await page.waitFor(2000);
await page.screenshot({
path: 'stats.png',
fullPage: true
})
browser.close();
};
scrape();
EDIT: i will take a fullscreen screenshot of the page then use jimp module to crop it so mainly i have to figure out how to press the button
EDIT: im an idiot i was using the wrong selector my bad :)
Share Improve this question edited Mar 29, 2018 at 9:06 Ben W asked Mar 28, 2018 at 16:34 Ben WBen W 411 gold badge1 silver badge8 bronze badges2 Answers
Reset to default 1i was using the wrong selector the one i should have been using is:
#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a:nth-child(2)
so my code for people is:
var puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
var SELECTOR = "#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a:nth-child(2)";
await page.goto('https://fortnitetracker./profile/pc/Twitch.BadGuyBen');
await page.focus(SELECTOR);
await page.waitFor(2000);
await page.click(SELECTOR);
await page.screenshot({
path: 'stats.png',
fullPage: true
})
browser.close();
};
scrape();
await page.$eval('section[class="promocode__segment"]',
e => {e.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'end' })})
i am using puppeteer to try to take a screenshot of a website but first i have to press a button called "Lifetime" its selector is:
#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected
i have to first scroll down press the lifetime button and take a screenshot of the "solo", "duo" and "squad" stats like this:
target photo:
i am trying this in non-headless mode to make sure it works but it doesnt seem to be working. i have got my code to the point where it will scroll down to the element but not click it using page.click(SELECTOR). so far i have been able to open the webpage and scroll down but when i try to use page.click it does not work. i will worry about the screenshot later once i can figure out how to press the "lifetime" button
my code is:
var puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.goto('.BadGuyBen');
await page.tap('#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected');
await page.waitFor(2000);
await page.screenshot({
path: 'stats.png',
fullPage: true
})
browser.close();
};
scrape();
EDIT: i will take a fullscreen screenshot of the page then use jimp module to crop it so mainly i have to figure out how to press the button
EDIT: im an idiot i was using the wrong selector my bad :)
i am using puppeteer to try to take a screenshot of a website but first i have to press a button called "Lifetime" its selector is:
#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected
i have to first scroll down press the lifetime button and take a screenshot of the "solo", "duo" and "squad" stats like this:
target photo:
i am trying this in non-headless mode to make sure it works but it doesnt seem to be working. i have got my code to the point where it will scroll down to the element but not click it using page.click(SELECTOR). so far i have been able to open the webpage and scroll down but when i try to use page.click it does not work. i will worry about the screenshot later once i can figure out how to press the "lifetime" button
my code is:
var puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.goto('https://fortnitetracker./profile/pc/Twitch.BadGuyBen');
await page.tap('#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a.btn.btn-season.selected');
await page.waitFor(2000);
await page.screenshot({
path: 'stats.png',
fullPage: true
})
browser.close();
};
scrape();
EDIT: i will take a fullscreen screenshot of the page then use jimp module to crop it so mainly i have to figure out how to press the button
EDIT: im an idiot i was using the wrong selector my bad :)
Share Improve this question edited Mar 29, 2018 at 9:06 Ben W asked Mar 28, 2018 at 16:34 Ben WBen W 411 gold badge1 silver badge8 bronze badges2 Answers
Reset to default 1i was using the wrong selector the one i should have been using is:
#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a:nth-child(2)
so my code for people is:
var puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
var SELECTOR = "#profile > div.trn-profile.dtr-profile > div > div.content > div:nth-child(1) > div.material-card > a:nth-child(2)";
await page.goto('https://fortnitetracker./profile/pc/Twitch.BadGuyBen');
await page.focus(SELECTOR);
await page.waitFor(2000);
await page.click(SELECTOR);
await page.screenshot({
path: 'stats.png',
fullPage: true
})
browser.close();
};
scrape();
await page.$eval('section[class="promocode__segment"]',
e => {e.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'end' })})
本文标签: javascriptpuppeteer scroll and click on buttonStack Overflow
版权声明:本文标题:javascript - puppeteer scroll and click on button - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745607208a2158794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论