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 badges
Add a ment  | 

2 Answers 2

Reset to default 1

i 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 badges
Add a ment  | 

2 Answers 2

Reset to default 1

i 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