Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. const puppeteer = require('puppeteer');
  2. setInterval(()=>{
  3.  
  4.  
  5. (async () => {
  6. const browser = await puppeteer.launch({headless: false});
  7. const page = await browser.newPage();
  8. const url='https://adfslight.oswiatawradomiu.pl/LoginPage.aspx?ReturnUrl=%2f%3fwa%3dwsignin1.0%26wtrealm%3dhttps%253A%252F%252Fsynergia.librus.pl%252Floguj%252Fradom';
  9. await page.goto(url);
  10.  
  11. await page.type('#Username', 'j');
  12. await page.type('#Password', 'd');
  13. await page.click('.submit-button');
  14.  
  15. await page.waitForNavigation();
  16. await page.waitForNavigation();
  17. await page.goto('https://synergia.librus.pl/wiadomosci');
  18. //await page.screenshot({path: 'example.png'});
  19. e = await page.evaluate(() => {
  20. const messages = [];
  21. const unreadQuery = '.container-background > table > tbody > tr > td:nth-child(2n) > table:nth-child(2n) > tbody'+'> tr > td[style="font-weight: bold;"] ';
  22.  
  23. // const clickList = document.querySelectorAll(unreadQuery + '> a');
  24. const messList = document.querySelectorAll(unreadQuery);
  25.  
  26. messList.forEach((el, i) => {
  27. if(i%3==0) messages.push( {
  28. author: el.innerText,
  29. title: "",
  30. date: ""
  31. } );
  32. else if(i%3==1) messages[messages.length-1].title = el.innerText;
  33. else messages[messages.length-1].date = el.innerText;
  34. });
  35.  
  36.  
  37. return{
  38. messages
  39. }
  40. })
  41. for(let i=0;i<e.messages.length;i++){
  42. await page.click('.container-background > table > tbody > tr > td:nth-child(2n) > table:nth-child(2n) > tbody'+'> tr > td[style="font-weight: bold;"] '+' > a');
  43. await page.screenshot({path: `test${i}.jpg`, fullPage: true})
  44. await page.goBack();
  45. }
  46.  
  47.  
  48. await browser.close();
  49. const Time = new Date();
  50. console.log(`Jest ${Time.getHours}:${Time.getMinutes}:${Time.getSeconds} ${Time.getUTCDate}`);
  51. console.log(`Program odczytał ${e.messages.length} następujących wiadomości:`);
  52. e.messages.forEach(el=>{
  53. console.log(`${el.author}||${el.title}||${el.data}`);
  54. });
  55.  
  56. });
  57. }, 300);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement