Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't get page source. #6845

Closed
fengbin8606 opened this issue Jan 12, 2019 · 6 comments
Closed

I can't get page source. #6845

fengbin8606 opened this issue Jan 12, 2019 · 6 comments

Comments

@fengbin8606
Copy link

🐛 Bug Report

My code is:

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Test {

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver", "D:\\ChromeDriver\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    ChromeDriver driver = new ChromeDriver(options);
    driver.get("http://ccc.spdb.com.cn/news/qgxhd/");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println(driver.getPageSource());
    driver.quit();
}

}

To Reproduce

The result is :
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 6315
Only local connections are allowed.
一月 12, 2019 3:40:02 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: OSS
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>

Expected behavior

The page source of "http://ccc.spdb.com.cn/news/qgxhd/".

Environment

OS: Windows 7
Browser: Chrome
Browser version: 71.0.3578.98
Browser Driver version: ChromeDriver 2.45
Language Bindings version: Java 3.14.0
Selenium Grid version (if applicable):

@lilin3
Copy link

lilin3 commented Jan 12, 2019

if your os is windows, and you use headless chrome, you have to add argument "--disable-gpu".
you can google search the use of headless chrome.

@fengbin8606
Copy link
Author

I test argument "--disable-gpu","--allow-running-insecure-content","--disable-web-security","--enable-automation","--no-sandbox","--disable-infobars","--disable-dev-shm-usage","--disable-browser-side-navigation". The result is the same:<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>

@lilin3
Copy link

lilin3 commented Jan 14, 2019

last time I get empty page source is because the site use https and use unsafe ssl certificate.
if you are using https, see Michael Michelis'answer at https://stackoverflow.com/questions/47715071/chrome-headless-in-unix-returns-empty-page-source

@fengbin8606
Copy link
Author

fengbin8606 commented Jan 15, 2019

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Test {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "D:\\ChromeDriver\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");
        options.addArguments("--disable-gpu");
        options.addArguments("--allow-insecure-localhost");
        options.addArguments("--allow-running-insecure-content");
        options.addArguments("--ignore-certificate-errors");
        options.addArguments("--no-sandbox");
        options.addArguments("--window-size=1280,1000");
        options.setCapability("acceptSslCerts", true);
        options.setCapability("acceptInsecureCerts", true);
        ChromeDriver driver = new ChromeDriver(options);
        driver.get("http://ccc.spdb.com.cn/news/qgxhd/");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(driver.getPageSource());
        driver.quit();
    }

}

The result is the same: <html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>

Environment

OS: Windows 7
Browser: Chrome
Browser version: 71.0.3578.98
Browser Driver version: ChromeDriver 2.45
Language Bindings version: Java 3.14.0
Selenium Grid version (if applicable):

@lilin3
Copy link

lilin3 commented Jan 15, 2019

I found that there are two errors in the chrome console log, maybe printing out it can help you.
I have no solution.
if you don't use headless mode, it works fine

@barancev
Copy link
Member

Please report this issue to https://bugs.chromium.org/p/chromedriver/issues/list

@lock lock bot locked and limited conversation to collaborators Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants