1
如何創建HTML快照(服務器端)以將其提供給Google進行呈現(爬網),並且必須在AWS EC2實例(無頭服務器)上執行此操作。 那麼我應該怎麼做呢?在用於Google渲染的AWS EC2實例上創建HTML快照
如何創建HTML快照(服務器端)以將其提供給Google進行呈現(爬網),並且必須在AWS EC2實例(無頭服務器)上執行此操作。 那麼我應該怎麼做呢?在用於Google渲染的AWS EC2實例上創建HTML快照
這裏是它的答案:
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那inportant .....