Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // We'll use Puppeteer is our browser automation framework.
  2. const puppeteer = require('puppeteer');
  3. var fs = require('fs');
  4. var Client = require('ftp');
  5. // This is where we'll put the code to get around the tests.
  6. const preparePageForTests = async (page) => {
  7.   // Pass the User-Agent Test.
  8.   const userAgent = 'Mozilla/5.0 (X11; Linux x86_64)' +
  9.     'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36';
  10.   await page.setUserAgent(userAgent);
  11.  
  12.   // Pass the Webdriver Test.
  13.   await page.evaluateOnNewDocument(() => {
  14.     Object.defineProperty(navigator, 'webdriver', {
  15.       get: () => false,
  16.     });
  17.   });
  18.  
  19.   // Pass the Chrome Test.
  20.   await page.evaluateOnNewDocument(() => {
  21.     // We can mock this in as much depth as we need for the test.
  22.     window.navigator.chrome = {
  23.       runtime: {},
  24.       // etc.
  25.     };
  26.   });
  27.  
  28.   // Pass the Permissions Test.
  29.   await page.evaluateOnNewDocument(() => {
  30.     const originalQuery = window.navigator.permissions.query;
  31.     return window.navigator.permissions.query = (parameters) => (
  32.       parameters.name === 'notifications' ?
  33.         Promise.resolve({ state: Notification.permission }) :
  34.         originalQuery(parameters)
  35.     );
  36.   });
  37.  
  38.   // Pass the Plugins Length Test.
  39.   await page.evaluateOnNewDocument(() => {
  40.     // Overwrite the `plugins` property to use a custom getter.
  41.     Object.defineProperty(navigator, 'plugins', {
  42.       // This just needs to have `length > 0` for the current test,
  43.       // but we could mock the plugins too if necessary.
  44.       get: () => [1, 2, 3, 4, 5],
  45.     });
  46.   });
  47.  
  48.   // Pass the Languages Test.
  49.   await page.evaluateOnNewDocument(() => {
  50.     // Overwrite the `plugins` property to use a custom getter.
  51.     Object.defineProperty(navigator, 'languages', {
  52.       get: () => ['en-US', 'en'],
  53.     });
  54.   });
  55. }
  56.  
  57. (async () => {
  58.   // Launch the browser in headless mode and set up a page.
  59.   const browser = await puppeteer.launch({
  60.     args: ['--no-sandbox'],
  61.     headless: true,
  62.   });
  63.   const page = await browser.newPage();
  64.  
  65.   // Prepare for the tests (not yet implemented).
  66.   await preparePageForTests(page);
  67.  
  68.   // Navigate to the page that will perform the tests.
  69.   const testUrl = 'https://www.partypoker.com/feeds/PokerTourneyFeed_PARTYPOKER_en_US.js';
  70.   await page.goto(testUrl);
  71.  
  72.   // Save a screenshot of the results.
  73.   //await page.screenshot({path: 'headless-test-result.png'});
  74.  
  75.  
  76.   //const html = await page.content();
  77.   //fs.writeFile('partygaming_tournament_feed.json', html, _ => console.log('HTML saved'));
  78.  
  79.   innerText = await page.evaluate(() =>  {
  80.         //return JSON.parse(document.querySelector("body").innerText);
  81.         return document.querySelector("body").innerText;
  82.     });
  83.  
  84.   //console.log(innerText);
  85.   fs.writeFile('partygaming_tournament_feed.json', innerText, _ => console.log('json saved'));
  86.  
  87.   // Clean up.
  88.   await browser.close();
  89.  
  90.  
  91.   var c = new Client();
  92.   c.on('ready', function() {
  93.     c.put('partygaming_tournament_feed.json', 'partygaming_tournament_feed.json', function(err) {
  94.       if (err) throw err;
  95.       c.end();
  96.     });
  97.   });
  98.   // connect to localhost:21 as anonymous
  99.   c.connect({
  100.         host: "91.218.99.1",
  101.         port: 21,
  102.         user: "ftpacc@xxx.com",
  103.         password: "123123231r",
  104.         debug: console.log
  105.     });
  106.  
  107. console.log(c);
  108.  
  109.  
  110.  
  111. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement