如何创建HTML快照,服务器端,将其提供给Google进行渲染(抓取),我必须在AWS EC2实例(无头服务器)上执行此操作。 那我该怎么办呢?
答案 0 :(得分:1)
以下是答案:
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();
并在您的ec2实例上安装xvfb和firefox,这些内容很重要.....