Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We'll use Puppeteer is our browser automation framework.
- const puppeteer = require('puppeteer');
- var fs = require('fs');
- var Client = require('ftp');
- // This is where we'll put the code to get around the tests.
- const preparePageForTests = async (page) => {
- // Pass the User-Agent Test.
- const userAgent = 'Mozilla/5.0 (X11; Linux x86_64)' +
- 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36';
- await page.setUserAgent(userAgent);
- // Pass the Webdriver Test.
- await page.evaluateOnNewDocument(() => {
- Object.defineProperty(navigator, 'webdriver', {
- get: () => false,
- });
- });
- // Pass the Chrome Test.
- await page.evaluateOnNewDocument(() => {
- // We can mock this in as much depth as we need for the test.
- window.navigator.chrome = {
- runtime: {},
- // etc.
- };
- });
- // Pass the Permissions Test.
- await page.evaluateOnNewDocument(() => {
- const originalQuery = window.navigator.permissions.query;
- return window.navigator.permissions.query = (parameters) => (
- parameters.name === 'notifications' ?
- Promise.resolve({ state: Notification.permission }) :
- originalQuery(parameters)
- );
- });
- // Pass the Plugins Length Test.
- await page.evaluateOnNewDocument(() => {
- // Overwrite the `plugins` property to use a custom getter.
- Object.defineProperty(navigator, 'plugins', {
- // This just needs to have `length > 0` for the current test,
- // but we could mock the plugins too if necessary.
- get: () => [1, 2, 3, 4, 5],
- });
- });
- // Pass the Languages Test.
- await page.evaluateOnNewDocument(() => {
- // Overwrite the `plugins` property to use a custom getter.
- Object.defineProperty(navigator, 'languages', {
- get: () => ['en-US', 'en'],
- });
- });
- }
- (async () => {
- // Launch the browser in headless mode and set up a page.
- const browser = await puppeteer.launch({
- args: ['--no-sandbox'],
- headless: true,
- });
- const page = await browser.newPage();
- // Prepare for the tests (not yet implemented).
- await preparePageForTests(page);
- // Navigate to the page that will perform the tests.
- const testUrl = 'https://www.partypoker.com/feeds/PokerTourneyFeed_PARTYPOKER_en_US.js';
- await page.goto(testUrl);
- // Save a screenshot of the results.
- //await page.screenshot({path: 'headless-test-result.png'});
- //const html = await page.content();
- //fs.writeFile('partygaming_tournament_feed.json', html, _ => console.log('HTML saved'));
- innerText = await page.evaluate(() => {
- //return JSON.parse(document.querySelector("body").innerText);
- return document.querySelector("body").innerText;
- });
- //console.log(innerText);
- fs.writeFile('partygaming_tournament_feed.json', innerText, _ => console.log('json saved'));
- // Clean up.
- await browser.close();
- var c = new Client();
- c.on('ready', function() {
- c.put('partygaming_tournament_feed.json', 'partygaming_tournament_feed.json', function(err) {
- if (err) throw err;
- c.end();
- });
- });
- // connect to localhost:21 as anonymous
- c.connect({
- host: "91.218.99.1",
- port: 21,
- user: "ftpacc@xxx.com",
- password: "123123231r",
- debug: console.log
- });
- console.log(c);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement