Results 1 to 7 of 7
Thread: WebEngine find text
- 09-11-2011, 01:43 AM #1
- 09-14-2011, 12:58 AM #2
Get html source code from HTMLDocument
I am using JavaFX's web browser engine.
I need to get the HTML's page source code from org.w3c.dom.html.HTMLDocument. I have been trying to do this for 2 days and I can't figure out how to do it.
How can I do this?
I have posted a similar thread on JavaFX section as well but I got no answers. So I thought I will post this on here. :P
- 09-14-2011, 01:12 AM #3
Re: Get html source code from HTMLDocument
If you used a URLConnection, you would just read it from the site.
- 09-14-2011, 01:23 AM #4
Re: Get html source code from HTMLDocument
I'm not using URLConnection.
I'm using JavaFX for the web browser, because I don't really know how to make a web browsers. I have tried to make one but I failed. I know that it would be possible to get the source code with URLConnection but what if you need to be logged in ? For example I would like to find out how many private message I have received using the URLConnection, if I will try it - it will say that I will need to login to see the private messages.
But in JavaFX there is a web engine and you can get the page's document and other elements of the page. But I just cant figure out how to get the whole source code.
Another question: would it be hard to make a web browser in java (without Java FX)?
- 09-14-2011, 06:49 AM #5
Re: WebEngine find text
Lets keep this all in one place. I've merged the two threads.
I don't know of any way to get the raw HTML from WebEngine, but as you've been told you can use URLConnection. Use the right tool for the job and all that.
You can get the page text by usingdbJava FX Code:webEngine.getDocument().getDocumentElement().getTextContent()
- 09-15-2011, 05:55 PM #6
Re: WebEngine find text
I've used webEngine.getDocument().getDocumentElement() to get the elements of my page. :P
But I got an another problem. I don't know whether or not I should make a new thread.
But I have a thread to check some things and then load a new page.
I have used this for my loading: Main.Browser.getBrowser().getEngine().load(Constan ts.PageURLS.RACE.getURL());
The URL is http://lt1.website.lt/race.php
And the URL is a String.
But when it tries to load the page I get this error:
What am I doing wrong?Java FX Code:Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4 at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:218) at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:373) at javafx.scene.web.WebEngine.checkThread(WebEngine.java:581) at javafx.scene.web.WebEngine.load(WebEngine.java:385) at org.srbot.bot.Loop.startLoop(Loop.java:71) at org.srbot.bot.Loop.run(Loop.java:26) at java.lang.Thread.run(Thread.java:662)
Here is my thread:
Java FX Code:while (isRunning) { System.out.println("Loop started"); if (!m.isRacing() && !Methods.getURL().contains(BotConstants.PageURLS.RACE.getURL())) { Methods.setStatus("Loading " + BotConstants.PageURLS.RACE.getURL()); Methods.println("Loading page..."); Main.Browser.getBrowser().getEngine().load(BotConstants.PageURLS.RACE.getURL()); Methods.println("Done loading page"); } else if (Methods.getURL().contains(BotConstants.PageURLS.RACE.getURL())) { Methods.setStatus("Starting race... " + BotConstants.PageURLS.RACE.getURL()); } else { Methods.setStatus("Waiting for race to be finished."); } }Last edited by PhQ; 09-15-2011 at 06:02 PM.
- 09-15-2011, 08:46 PM #7
Similar Threads
-
Find a text in a file and write a word following this word
By lemontree45 in forum New To JavaReplies: 3Last Post: 08-30-2011, 04:44 PM -
Searching through folder to find text inside all files
By dazzabiggs in forum New To JavaReplies: 3Last Post: 05-03-2011, 01:20 PM -
How to find specific text from .txt file
By krechlich in forum New To JavaReplies: 11Last Post: 03-18-2011, 06:57 AM -
Find and Replace in Text File
By hamidsharifi in forum New To JavaReplies: 2Last Post: 02-13-2011, 02:01 AM -
find and replace text from a text file
By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks