Search code examples
amazon-ec2amazon-web-servicesrenderinggoogle-crawlers

Create HTML snapshot on AWS EC2 instance for Google rendering


How can I create an HTML snapshot, server side, to provide it to Google for rendering(Crawling) and I have to do it on AWS EC2 instance which is the headless server. So how should I go about this?


Solution

  • Here is the answer for it:

        String Xport = System.getProperty("lmportal.xvfb.id", ":99");
    final File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path", "/opt/firefox/firefox"));
    FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
    firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
    
    FirefoxDriver driver = new FirefoxDriver(firefoxBinary,null);
    
    driver.get(url);
    
    Thread.sleep(1500);
    res.setContentType("text/html;charset=UTF-8");
    PrintWriter out = res.getWriter();
    String str = driver.getPageSource();
    out.println(str);
    
    out.close();
    driver.quit();
    

    And install the xvfb and firefox on your ec2 instance thats inportant.....