metalx1000

Check if Sam's Club product is in stock

May 2nd, 2020
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/phantomjs
  2. /*    
  3. @licstart  The following is the entire license notice for the
  4. JavaScript code in this page.
  5.  
  6. Copyright (C) 2020 Kris Occhipinti - https://filmsbykris.com
  7.  
  8. The JavaScript code in this page is free software: you can
  9. redistribute it and/or modify it under the terms of the GNU
  10. General Public License (GNU GPL) as published by the Free Software
  11. Foundation, either version 3 of the License.
  12. The code is distributed WITHOUT ANY WARRANTY;
  13. without even the implied warranty of MERCHANTABILITY or FITNESS
  14. FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
  15.  
  16. As additional permission under GNU GPL version 3 section 7, you
  17. may distribute non-source (e.g., minimized or compacted) forms of
  18. that code without the copy of the GNU GPL normally required by
  19. section 4, provided you include this license notice and a URL
  20. through which recipients can access the Corresponding Source.  
  21.  
  22. https://www.gnu.org/licenses/gpl-3.0.txt
  23.  
  24. @licend  The above is the entire license notice
  25. for the JavaScript code in this page.
  26. */
  27.  
  28. var products = [
  29.   "https://www.samsclub.com/p/charmin-ultra-strong-toilet-paper-24-mega-plus-roll-bath-tissue/prod22890194",
  30.   "https://www.samsclub.com/p/organic-evoo-2-ltr/prod21330023"
  31. ]
  32.  
  33. for(i in products){
  34.   var time = i * 4000;
  35.   setTimeout(function(url){
  36.     go(url);
  37.   },time,products[i]);
  38. }
  39.  
  40. var time_exit = products.length * 4000 + 3000;
  41. setTimeout(function(){
  42.   phantom.exit();
  43. },time_exit);
  44.  
  45. function go(url){
  46.   console.log("===============================");
  47.   console.log(url);
  48.   var page = new require('webpage').create();
  49.   page.open(url, function(status) {
  50.     window.setTimeout(function() {
  51.       //page.render("page.png");
  52.       content = page.content.split("<");
  53.       for(c of content){
  54.         if(c.includes("sc-channel-stock-status")){
  55.           console.log(c.split(">")[1]);
  56.         }else if(c.includes("sc-product-header-title-container")){
  57.           console.log(c.split(">")[1]);
  58.         }
  59.       }
  60.       //phantom.exit();
  61.     }, 2000);
  62.   });
  63. }
Add Comment
Please, Sign In to add comment