2017-06-13 64 views
0
 
The second page cannot be read in phantomjs --my code is below 

var webPage = require('webpage');
var page = webPage.create();
page.onLoadFinished = function(){

var title = page.evaluate(function()
{
return document.querySelector("#link1").innerText;
});
console.log(title);

page.evaluate(function(args)
{
document.querySelector("#link1").click();

});

page.onLoadFinished = function(){

var title1 = page.evaluate(function()
{
return document.querySelector("#div1").innerText;
});
console.log(title1);
phantom.exit();
};
};

page.open('http://staging.eubookingsdata.com/scrape1.php', function(status) {

});
Here the first page is "http://staging.eubookingsdata.com/scrape1.php" I want to read the content of div in "http://staging.eubookingsdata.com/scrape2.php" Every thing is working fine ,but when i add target="_blank" in scrape1.php "link" it stopped working. scrape1.php <html>
<body>
<a id="link1" name="link1" href="scrape2.php" target="_blank" >click</a>
</body>
</html> scrape2.php <html>
<body>

<div id="div1" name="div1">hello world</div>
</body>

</html>

回答

0

var webPage = require('webpage');
var page = webPage.create();
page.onLoadFinished =函數()//第一水平

{

變種標題= page.evaluate(函數()
{
返回document.querySelector( 「#LINK1」)的innerText。
});
console.log(title);


//變種NEWPAGE = webPage.create()//第一水平
;
// var page1 = page.pages [0];

page.evaluate(函數(參數){//第一級

document.querySelector( 「#LINK1」)點擊();

});


};
page.onPageCreated = function(newPage){
newPage.onLoadFinished = function(status){//第二級
console.log(status);
VAR TITLE1 = newPage.evaluate(函數()
{
返回document.querySelector( 「#DIV1」)的innerText;
});
console.log(title1); //第2級
phantom.exit();
};
};
page.open( 'http://staging.eubookingsdata.com/scrape1.php',功能(狀態)

{
的console.log( 「第1頁」);

});

相關問題