I 'am Using jxbrowser ,
I want to download list of urls using browser.saveWebpage
public class Downloader{
public Downloader(String url) {
System.setProperty("teamdev.license.info", "true");
LoggerProvider.getChromiumProcessLogger().setLevel(Level.OFF);
Browser browser = new Browser(BrowserType.LIGHTWEIGHT);
browser.addLoadListener(new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()){
String filePath = "D:\\Downloads\\index"+System.currentTimeMillis()+".html";
String dirPath = "D:\\Downloads\\resources";
event.getBrowser().saveWebPage(filePath, dirPath, SavePageType.ONLY_HTML);
}
}
});
browser.loadURL(url);
if(!browser.isLoading())
{
browser.stop());
}
}
public static void main(String args[])
{
JxBrowserDemo jxBrowserDemo=null;
String yourInputFile="D:/file.txt";
ArrayList<String> lines=getUrls(yourInputFile); //read urls from file
for(int i=0; i<lines.size(); i++)
{
Thread.sleep(5000);
jxBrowserDemo=new JxBrowserDemo(lines.get(i));
}
}
}
saving pages works fine until specific time then it throws this exception
Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa der.java:58) Caused by: com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: Failed to g et Browser browserChannel 969 at com.teamdev.jxbrowser.chromium.Browser.a(SourceFile:376) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:200) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:172) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:139) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:125) at com.teamdev.jxbrowser.chromium.demo.JxBrowserDemo.(JxBrowserDem o.java:67) at com.teamdev.jxbrowser.chromium.demo.JxBrowserDemo.main(JxBrowserDemo. java:143) ... 5 more
please any help :)
"Failed to get Browser browserChannel 969" message most likely indicates that for some reason Chromium engine failed to create browser instance and open channel for it.
Chromium engine might have some limits for the number of browser instances created at the same time. These limits might be dependent on memory size, environment configuration, etc. As you have already created 968 browser instances without disposing them, that could be the reason of this exception.
Also please pay attention that you have a memory leak because you create new Browser instance for each URL and do not invoke the dispose()
method after this URL Browser instance processed it's URL.
The browser.stop();
line is unnecessary.
Right after invoking the saveWebPage() method you should wait until web page is saved and dispose browser instance.
Please take a look at the sample code below:
final int maxWaitingTime = 10000;
final int sleepTime = 50;
int currentWaitingTime = 0;
File indexHTML = new File(filePath);
File resourcesFolder = new File(dirPath);
while (!indexHTML.exists() || !resourcesFolder.exists()) {
TimeUnit.MILLISECONDS.sleep(sleepTime);
currentWaitingTime += sleepTime;
if (currentWaitingTime == maxWaitingTime)
throw new RuntimeException(new TimeoutException("The web page could not be saved."));
}
event.getBrowser().dispose();