Skip to content

Instantly share code, notes, and snippets.

@Sanjay007
Created April 15, 2019 20:31
Show Gist options
  • Save Sanjay007/0deaae32c5af31b46dff5a44cc26c999 to your computer and use it in GitHub Desktop.
Save Sanjay007/0deaae32c5af31b46dff5a44cc26c999 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
var fs = require("fs");
const FORM_SELECTOR='form div>div input';
const SUGGESTION_SELECTOR='form div>div ul>li';
async function run() {
const browser = await puppeteer.launch({headless: false}); // default is true
const page = await browser.newPage();
await page.goto('https://www.google.com/intl/en-GB/gmail/about/#');
await page.waitFor(5000)
const dd=await page.$x("//a[contains(text(),'Sign in')]");
const pageTarget = page.target();
await dd[0].click();
//console.log(dd);
await page.waitFor(5000)
const newTarget = await browser.waitForTarget(target => target.opener() === pageTarget); //check that you opened this page, rather than just checking the url
const newPage = await newTarget.page(); //get the page object
await newPage.type('#identifierId','****', { delay: 100 })
await newPage.click('#identifierNext > content');
await page.waitFor(5000)
await newPage.type('#password input','****', { delay: 100 })
await newPage.click('#passwordNext > content > span ');
await newPage.goto(' https://ads.google.com/aw/keywordplanner/home');
await newPage.type('#identifierId','*****', { delay: 100 })
await newPage.click('#identifierNext > content');
await page.waitFor(5000)
await newPage.type('#password input','****', { delay: 100 })
await newPage.click('#passwordNext > content > span ');
try {
await newPage.waitForNavigation({timeout: 60000, waitUntil: ['domcontentloaded']})
} catch (error) {
// console.log(error)
}
newPage
.waitForXPath("//div[contains(text(), 'Keyword Planner')]")
.then((data) => console.log("found"));
// await page.click(FORM_SELECTOR);
// await page.keyboard.type('Spring security');
//await page.type('input[name=q]', 'puppeteer', { delay: 100 })
await newPage.close();
const page2 = await browser.newPage();
await page2.goto(' https://ads.google.com/aw/keywordplanner/home');
await page2.waitFor(5000);
let news=await page2.evaluate(() => {
document.querySelectorAll('.cards-container > div material-icon.arrow-icon')[1].click();
});
var contents = fs.readFileSync('hackernews.json', 'utf8');
await page2.type('textArea',contents, { delay: 100 });
let news2=await page2.evaluate(() => {
document.querySelectorAll('splash-view > div splash-cards > div material-ripple')[1].click();
});
// let news=await page.evaluate(() => {
// const SUGGESTION_SELECTOR='form div>div ul>li';
// let titleNodeList = document.querySelectorAll(SUGGESTION_SELECTOR);
// console.log("sssss",titleNodeList);
// // var ageList = document.querySelectorAll(`span.age`);
// // var scoreList = document.querySelectorAll(`span.score`);
// var titleLinkArray = [];
// for (var i = 0; i < titleNodeList.length; i++) {
// titleLinkArray[i] =
// titleNodeList[i].innerText
// // link: titleNodeList[i].getAttribute("href"),
// // age: ageList[i].innerText.trim(),
// // score: scoreList[i].innerText.trim()
// console.log(titleLinkArray);
// }
// return titleLinkArray;
// });
// //await browser.close();
// fs.writeFile("hackernews.json", JSON.stringify(news), function(err) {
// if (err) throw err;
// console.log("Saved!");
// });
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment