1

I need the source of the url given in the program. But the program returns oly some json data not the entire page source. What's the problem??

public class selenium
{
public static void main(String[] args)
{
    selenium.loadPage("http://photos.filmibeat.com/celebs/kajal-aggarwal/photos-c14-e13421-p592995.html");
}
public static void loadPage(String url)
{

    WebDriver driver = new FirefoxDriver();

    driver.get(url);

    String html = driver.getPageSource();

    System.out.println(html);

    driver.quit();        

}
}

3 Answers 3

2

I am just adding more info on @alecxe answer The solution provided by alecxe is working perfectly

The console output size of eclipse is by default only 80000 characters

enter image description here

Window > Preferences, go to the Run/Debug > Console section > then disable limit console option

or write data into a file

    File file = new File("path/filename.txt");
    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(content);
    bw.close();

Hope this helps you

Sign up to request clarification or add additional context in comments.

Comments

2

The problem is that you are getting the page source too early - the page is not yet loaded at that moment. Use an Explicit Wait to wait for a particular element on a page to become visible.

For instance, waiting for the photo list block to become visible:

WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("photoListBlock"));

Comments

2

The above problem can be handled by both Implicit and Explicit wait. Here i tried with Implicit wait with your code. Please try this. It worked for me with the below code.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Pagesource
{
public static void main(String[] args)
{
    Pagesource.loadPage("http://photos.filmibeat.com/celebs/kajal-aggarwal/photos-c14-e13421-p592995.html");
}
public static void loadPage(String url)
{
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get(url);

    String html = driver.getPageSource();

    System.out.println(html);

    driver.quit();      
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.