1.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { chromium } from "playwright";
  2. const browser = await chromium.launch({
  3. headless: false,
  4. devtools: true,
  5. });
  6. const page = await browser.newPage();
  7. await page.route("**/*", async (route, request) => {
  8. console.log(request.url());
  9. const resourceType = route.request().resourceType();
  10. if (["image", "font"].includes(resourceType)) {
  11. route.abort();
  12. } else if (/\/sp\/h/.test(request.url())) {
  13. route.abort();
  14. } else {
  15. route.continue();
  16. }
  17. });
  18. await page.goto("https://www.pcoptimum.ca/");
  19. const link = await page.$('a > span:has-text("sign in")');
  20. link.click();
  21. await page.waitForURL("https://accounts.pcid.ca/login");
  22. await page.fill('input[id="email"]', "linxiaojoe@hotmail.com");
  23. await page.fill('input[id="password"]', "Andy123456$");
  24. await page.click('button:has-text("Sign in")');
  25. console.log("xxx");
  26. await page.route("**/points", async (route, request) => {
  27. console.log(request.url());
  28. await route.continue();
  29. const response = await route.fetch();
  30. console.log(await response.json());
  31. });
  32. try {
  33. await page.waitForURL("https://www.pcoptimum.ca/dashboard");
  34. } catch (error) {
  35. console.log(error);
  36. console.log(page.url());
  37. await page.screenshot({ path: "error.png" });
  38. process.exit(1);
  39. }
  40. console.log("Logged in");
  41. await page.waitForTimeout(5000);
  42. const element = await page.$(".points-overview-balance");
  43. const text = await element.textContent();
  44. console.log(text);