Using multiple page.open in one script

后端 未结 2 838
臣服心动
臣服心动 2020-12-10 21:49

My goal is open many pages(with a short delay) and save my data to a file.

But my code does not work.

var gamesList = [url1,url2,url3];
//gamesList i         


        
2条回答
  •  再見小時候
    2020-12-10 22:15

    Explanation above is very helpful to me. So, thanx a lot. Come to the point, sometimes js function renders even after the page has already loaded, in this scenario setTimeout() method, is very helpful. And,I faced problem like this when scraping many site....I used setTimeout() method in this way,

    `

            function handle_page(url){page.open(url, function() {setTimeout(function() {var html_text=page.evaluate(function(){ 
                var is= document.querySelectorAll("li.bookinDetails_c1_180616")[0].textContent;
                var isbn=is.trim();
                //return s1;
                var w,x,y,z,z1,w1,u,a;
                a= document.querySelectorAll("li.selectableBook");
                if(a.length==5){
                    w1=document.querySelectorAll("span.bookPrice")[0].textContent;
                    w=w1.trim();
                    x1=document.querySelectorAll("span.bookPrice")[1].textContent;
                    x=x1.trim();
                    y1=document.querySelectorAll("span.bookPrice")[2].textContent;
                    y=y1.trim();
                    z1=document.querySelectorAll("span.bookPrice")[3].textContent;
                    z=z1.trim();
                    u=isbn+"=>["+"RENT USED:-"+w+","+"RENT NEW:-"+x+","+"BUY USED:-"+y+","+"BUY NEW:-"+z+"]";
                    return u;
                }else{
                    y1=document.querySelectorAll("span.bookPrice")[0].textContent;
                    y=y1.trim();
                    z1=document.querySelectorAll("span.bookPrice")[1].textContent;
                    z=z1.trim();
                    u=isbn+"=>["+"BUY USED:-"+y+","+"BUY NEW:-"+z+"]";
                    return u;
                }
    
            });
            fs.write('html.txt',html_text+'\r\n','a');
            next_page();
        }, 400);
    
    });
    }
    

    `

提交回复
热议问题