Reputation: 1
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>
Upvotes: 0
Views: 98
Reputation: 1
var webPage = require('webpage');
var page = webPage.create();
page.onLoadFinished = function() //1st level
{
var title = page.evaluate(function()
{
return document.querySelector("#link1").innerText;
});
console.log(title); //1st level
//var newPage = webPage.create();
//var page1=page.pages[0];
page.evaluate(function(args){ //1st level
document.querySelector("#link1").click();
});
};
page.onPageCreated = function(newPage){
newPage.onLoadFinished = function(status){ //2nd level
console.log(status);
var title1 = newPage.evaluate(function()
{
return document.querySelector("#div1").innerText;
});
console.log(title1);//2nd level
phantom.exit();
};
};
page.open('http://staging.eubookingsdata.com/scrape1.php', function(status)
{
console.log("page1");
});
Upvotes: 0