Hi all,
my problem is : i'm developing a crawler-like application,
until now, i've used a raw http connection for retrieving html that i
want to parse.
but now i need to send the POST data to retrieve the html of a site
that make eccessive use of javascript,
so i've considered to use JavaXPCOM to emded mozilla or firefox or
gecko, for compile the form and retrieve the html generated also from
javascript.
Now i've googled and googled... but nothing, i've found only about
embedding mozilla in a GUI (SWT).
Is there a way to do this without embedding also the GUI ? I'm using
Netbeans, so i can't use SWT (AWT seems that not already implemented)
I've tried with this code, but it gets me :
org.mozilla.xpcom.XPCOMException: The function "loadURI" returned an
error condition (0x8000ffff)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.callXPCOMMethod(Native
Method)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.invoke(XPCOMJavaProxy.java:
143)
at $Proxy2.loadURI(Unknown Source)
at embedmozilla.Main.main(Main.java:55)
public static void main(String[] args) {
Mozilla mozilla = Mozilla.getInstance();
GREVersionRange[] range = new GREVersionRange[1];
range[0] = new GREVersionRange("1.8.0", true, "1.9",
false);
// work with trunk nightly version 1.9a1 ^^
try {
File grePath = Mozilla.getGREPathWithProperties(range,
null);
LocationProvider locProvider = new
LocationProvider(grePath);
mozilla.initialize(grePath);
mozilla.initEmbedding(grePath, grePath, locProvider);
System.out.println("Initted embedding");
nsIComponentManager componentManager =
mozilla.getComponentManager();
nsIWebBrowser browser = (nsIWebBrowser)
componentManager.createInstanceByContractID("@mozilla.org/embedding/
browser/nsWebBrowser;1",
null, nsIWebBrowser.NS_IWEBBROWSER_IID);
/*------->*/
nsIWebNavigation webNavigation = (nsIWebNavigation)
browser.queryInterface(nsIWebNavigation.NS_IWEBNAVIGATION_IID);
webNavigation.loadURI("www.debian.org",
nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
nsIDOMDocument document = webNavigation.getDocument();
System.out.println(document);
browser.getContentDOMWindow().getDocument();
System.out.println("Terminating embedding");
mozilla.termEmbedding();
} catch (FileNotFoundException e) {
e.printStackTrace();
// this exception is thrown if
//greGREPathWithProperties cannot find a GRE
} catch (XPCOMException e) {
e.printStackTrace();
// this exception is thrown if initEmbedding failed
}
}
Any advice ?
Thanks to all!
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding