Getting the HTML of a page.

I wish I could retrieve as a string the HTML content of a page displayed by a webEngine.
I know this code works:
webEngine.getPage().getHtml(webEngine.getMainFrame());
But getPage() and getMainFrame() are not public.
What is the "official" way to get the HTML content of a page as a string?

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
// Getting the HTML of a page. "Getting the HTML of a page"
public class DocumentPrinter extends Application {
  public static final String CONTENT =
      "<dl>\n" +
      "<dt>Coffee</dt>\n" +
      "<dd>- black hot drink</dd>\n" +
      "<dt>Milk</dt>\n" +
      "<dd>- white cold drink</dd>\n" +
      "</dl>";
  public static void main(String[] args) { launch(args); }
  @Override public void start(Stage primaryStage) {
    // create view with some content in it.
    final WebView view = new WebView();
    view.getEngine().loadContent(CONTENT);
    view.setPrefSize(200, 100);
    // hold a log the view's document.
    final Label documentLabel = new Label();
    // write the document to the document label
    view.getEngine().documentProperty().addListener(new ChangeListener<Document>() {
      @Override public void changed(ObservableValue<? extends Document> observableValue, Document oldValue, Document webViewDocument) {
        try {
          Node originalRoot = webViewDocument.getDocumentElement();
          // copying the document is necessary in this case because the serializer
          // we are using is not realized by the webview document implementation.
          // if you used a different serialization library, perhaps the copy step would not be required.
          // http://stackoverflow.com/questions/5226852/cloning-dom-document-object
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document copiedDocument = db.newDocument();
          Node copiedRoot = copiedDocument.importNode(originalRoot, true);
          copiedDocument.appendChild(copiedRoot);
          // weird dom api for serialization.
          // http://stackoverflow.com/questions/1219596/how-to-i-output-org-w3c-dom-element-to-string-format-in-java
          DOMImplementationLS domImplLS = (DOMImplementationLS) copiedDocument.getImplementation();
          LSSerializer serializer = domImplLS.createLSSerializer();
          // update the document label with serialized document.
          documentLabel.setText(serializer.writeToString(copiedRoot));
        } catch (ParserConfigurationException e) {
          e.printStackTrace();
    // layout the scene.
    final VBox layout = new VBox(10);
    layout.setStyle("-fx-padding: 10; -fx-background-color: cornsilk");
    layout.getChildren().addAll(
      new Title("Web View"),          view,
      new Title("Original Content"),  new Label(CONTENT),
      new Title("Rendered Document"), documentLabel
    primaryStage.setScene(new Scene(layout, 450, 450));
    primaryStage.show();
  class Title extends Label {
    Title(String titleString) { super(titleString); setStyle("-fx-font-weight: bold;"); }
}

Similar Messages

  • How to get the html source for these web page ?

    My code work well for standart page, but I'm unable to get the html source from these page with my vb program :
    http://www.slashdot.org
    http://userfriendly.org
    http://segfault.org
    here my code
    private sub commandgethtml_Click ()
    Inet1.Cancel
    Inet1.Protocol = icHTTP
    Inet1.URL = theURL
    HTMLcode = Inet1.OpenURL(theURL, icString)
    RichTextBox1.Text = HTMLcode
    end sub
    thanks in advance.

    Hello Cyrano,
    This Developer Forum focuses on the National Instruments product "Measurement Studio for Visual Basic" (formerly known as ComponentWorks). Our goal is to help people to better integrate this product into their test, measurement, and automation applications. Your question directly pertains to the Microsoft Internet Transfer Control. I think you would find an increased number of responses that are better focused on your question if you would repost it to a forum that specializes in general VB and internet programming. Good luck!
    Jeremiah Cox
    Applications Engineer
    National Instruments
    http://www.ni.com/ask

  • Can I design something in Muse and somehow get the HTML text fro it to plug into Business Catalyst to make a newsletter?

    I guess since I don't know html, I was wondering if I could create a "page" in muse and somehow get the "HTML" text from it so I can plug that text into a Business Catalyst E-Mail Marketing Campaign template. since I am struggling so much with modifying one of Business Catalysts established templates.
    I made my website with muse and I host it through Business Catalyst with a webMarketing Plan.
    Thanks in advance,

    There is no direct way to achieve this but you may try a workaround which may work but would require testing on your end.
    Create the site in Muse and publish to BC , master page will be included in template section. So in your published site , Page template will show you design from Muse.
    Now from Partner portal , you can select the site to create email campaign template but please note that creating a template from PP will remove the default email campaign templates on BC end.
    After creating the campaign template from PP , login to your site and create email campaign and in template section you will get the option to select the template which you created from PP.
    Not an ideal way but can be used as a workaround.
    Thanks,
    Sanjit

  • How to get the HTML Source code from the active browser ?

    Hi All,
    I need to get the HTML Source code from the active browser (IE). I tried with the below code, but I am not able to get the Source code all the time, with respect to the different applications (http or https) and the user authentication has to be changes in few applications (_I dont know or not able to given that in the below code_). More over there is also a dependence of the URL to get the HTML Source code.
    Therefore what I feel is getting the HTML Source code from the given or active browser will be consistent than the URL. Since the Source code is available in the browser (IE) . Please help me with a sample code to achieve this . . . !
    HTMLDocument doc=(HTMLDocument) kit.createDefaultDocument();
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    URL url = new URL(strURL);
    Reader HTMLReader = new InputStreamReader(url.openConnection().getInputStream());
    kit.read(HTMLReader, doc, 0);Thanks in advance,
    Regards,
    Jothi Venkatachalam
    Edited by: j0o on May 7, 2009 3:11 AM

    The simple answer is: you don't.
    Not only is it simply not possible, but the entire concept of "the active browser" doesn't exist.
    You were on the right track with your code to retrieve the page directly from the server, but as you noticed that code will only work for regular http connections.
    For https and other protocols you will need to use appropriate libraries for each protocol. Something like Apache Commons can help you with that. There are networking libraries in there for a lot of commonly used protocols.

  • Can't get the HTML for My iTunes widgets

    Couple of things.
    My iTunes:
    I have enabled the My iTunes (Purchases, Favorites and Reviews). However, when I click the "Get HTML" buttons, I'm taken to the web page for getting the HTML. The image states that I haven't enabled My iTunes. Nothing that I have tried is working. Any ideas?
    Searches:
    The query handling when searching for topics doesn't actually work correctly. I searched for the string "My iTunes" and got 329 results, with every result on the first 4 pages (I stopped after looking at the first 40) were based on having "iTunes" in it. The results were not limited by the phrase "My iTunes". So, if there is a solution to this, the query results aren't providing information that makes it easy to find the right answers.
    Thanks much,

    Hello Jay Hill
    If the steps below are what you went through. You may wish to sign out of your iTunes account, sign back in, and attempt to get HTML code, if it still does not work, Uncheck all 3 boxes in your account and apply the info. So it shows that you need to enable the service. Enable it again by checking proper boxes.
    Also if you have not done so download the latest iTunes below
    http://www.apple.com/itunes/download/
    1. Launch iTunes
    2. In the iTunes menu bar click on Store - Sign into account if needed otherwise choose view my account. If you have to sign in, go back to same spot then choose view my account
    3.On the Apple Account information page near the bottom you will see something called My iTunes, and on the right hand side a button called Enable My iTunes.
    Once you press this will you be given information to read and a box to check and agree to. Then click continue.
    From there check all the applicable boxes that interest you. Once the boxes are checked, each one will offer a Get HTML Code, Press done in iTunes when you are finished. Feature should now be enabled.

  • How to get the total number of pages printed in a report?

    Hi All,
    I have a requirement where I need to print a frame of fields only in the last page. Unfortunately I cannot use the 'Print Object On' property as it doesnt work in my case. So, I am planning to write a format trigger on the frame to return TRUE if the page is the last physical page. Now, I need to know how to get the total number of physical pages that will get printed in the report so that I can use this to manipulate the frame. I was planning to use the 'Total Physical Pages' built-in, but it seems like I can just use it to print in a field and I can't use this field's value anywhere in the plsql code (formula column function/format trigger) in the report. Is there anyway to get the total number of pages printed in the report which can be used in the report plsql code?
    Thanks,
    Srini.

    i found the solution, thanks

  • How can I get the styleID of a page

    Hi all,
    my problem is to get the style_id of a page with java methods.
    Everythig else I can get, but not the style_id!!!
    I need it for using the same style in a popup window.
    Best regards, Michael

    I don't think you can get the style_id using the current implemenation. I'm assuming you're using web providers written in Java. A convoluted way would be to use a JDBC call back to the portal.

  • How can I get the HTML codes in illustrator?

    Hi, I am a graphic designer, and I am getting into the web world, I wanna know how can I get the HTML codes to upload a web design made using Illustrator,...¡?Does any one know?Please let me know...

    everyone here is right, dreamweaver is better and you will need to understand html for this to work. HOWEVER, you can make a functional website using just illustrator and notepad (or text edit if you're on a mac).
    Design your site in illy, slice it up with the slice tool. http://s23.postimg.org/mv311kpp7/test_illy.jpg 
    Save for web and select html and images, you'll get an html file and an images folder. Open the HTML file in your text editing program and it will look like this: http://s10.postimg.org/f32nf6r2h/html_stuff.jpg   you'll have to know HTML codes but you can find tutorials online for most stuff, you'll just have to figure it out. In my fake site, i linked a button to google so i had to add <a href> tags to the code. http://s22.postimg.org/5avpadhch/a_href.jpg  save the html file and open it in your web browser, hopefully not IE. You can't tell in the picture but the middle button actually does link to google. http://s21.postimg.org/qd77slqmf/firefox.jpg

  • When I click on my Yahoo bookmarks, I only get the download Yahoo toolbar page, I downloaded the toolbar again and I still get the same page when I hit bookmark icon - how do I get my bookmarks back - they still show on Microsoft Explorer

    Question
    When I click on my Yahoo bookmarks, I only get the download Yahoo toolbar page, I downloaded the toolbar again and I still get the same page when I hit bookmark icon - how do I get my bookmarks back - they still show on Microsoft Explorer

    julianscars wrote:
    I don't get a page, all I get is the player popping
    Click the green jelly button at the top left of the player.

  • How Can i get the URL of a page

    How Can i get the URL of a page . like in ASP the
    Request.QueryString() ...
    Thanks

    Are you wanting actual URL or just the url (query string
    variables)?
    For url variables you would reference the structure.variable
    name like so:
    #url.variablename#
    So if you had a url like this:
    http://www.somedomain.com?page=home&action=view
    You could access the variables like so:
    #url.page#
    #url.action#
    If you are wanting to actual page you could use:
    #cgi.script_name#
    Bryan Ashcraft (remove brain to reply)
    Web Application Developer
    Wright Medical Technologies, Inc.
    =============================
    Macromedia Certified Dreamweaver Developer
    Adobe Community Expert (DW) ::
    http://www.adobe.com/communities/experts/
    "Yasmin_lady" <[email protected]> wrote in
    message
    news:e4fhjv$fpl$[email protected]..
    > How Can i get the URL of a page . like in ASP the
    Request.QueryString()
    > ...
    > Thanks

  • I continue to get the /.HTML/Rce.Gen3 virus through my mailbox almost daily.  It is picked up by my anti-virus software.  How do I get rid of this permanently so I stop getting it daily?  Is it from a internet cache??

    I continue to get the /.HTML/Rce.Gen3 virus through my mailbox almost daily.  It is picked up by my anti-virus software.  How do I get rid of this permanently so I stop getting it daily?  Is it from a internet cache??

    I use MacKeeper on my MacBook Pro
    Ack! Get rid of that immediately! MacKeeper's bad news. Plus, it does a really awful job of actually detecting malware. See:
    Beware MacKeeper
    Mac anti-virus detection rates
    http://applehelpwriter.com/2011/09/21/how-to-uninstall-mackeeper-malware/
    My active accounts are clean, but the On My Mac gmail keeps and continues to repopulate all email, even after I trash them.
    If you're seeing messages remaining in GMail's All Mail folder after deleting them, that's normal. GMail keeps all messages in there, even after deletion, unless you manually delete stuff using GMail's web interface. See Hiding GMail’s “All Mail” from Apple Mail.
    If you're actually having trouble deleting e-mail from an On My Mac mailbox, there's probably something wrong with your mailboxes.

  • Getting the total number of pages inside a report

    Post Author: jportelas
    CA Forum: .NET
    Good afternoon:
    How can I get the total number of pages inside a reportdocument object???
    I'm currently using VS.NET 2005.
    Thanks for the help.

    There's no public API to get this info directly from RAS.
    Option is to either walk through pages in the CrystalReportViewer till you get to the end, or use the non-public not-for-public use API:
    int lastPageNumber = ((com.crystaldecisions.sdk.occa.report.application.AdvancedReportSource) reportClientDocument.getReportSource()).getLastPageNumber(new com.crystaldecisions.sdk.occa.report.reportsource.RequestContext());
    Sincerely,
    Ted Ueda

  • Unable to download itunes...I only get the 'thanks for downloading page.'

    I have been unable to download the Win 64 bit version on multiple browsers (Chrome and Internet Explorer) all day. I only get the 'thanks for downloading page.'  Any ideas on what I can do?

    Troubleshooting issues with iTunes for Windows updates - MSVCR80

  • How to clean the html code multiple pages simultaneously with Dreamweaver or other soft ?

    hello,
    How to clean the html code multiple pages simultaneously with Dreamweaver or other soft ? I have hundreds of pages to clean
    Thanks !

    I would start afresh. I would also use Dreamweaver's template system to make thing a lot easier. Have a look at the following, copy and paste into a new document and view in your favourite browser.
    <!doctype html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
    <script type="text/javascript" src="ScriptLibrary/jquery-latest.pack.js"></script>
    <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <style>
    .hline {
        background: url(http://yannick.michelat.free.fr/barre.gif);
        height: 10px;
        margin-top: 10px;
        margin-bottom: 10px;
    </style>
    </head>
    <body>
    <div class="container">
        <div class="row">
            <div class="col-xs-7">
                <img alt="" class="img-responsive pull-right" style="margin-top:20px;" src="http://yannick.michelat.free.fr/Calanques.gif" />
            </div>
            <div class="col-xs-5">
                <img alt="" class="img-responsive center-block" style="margin-top: 40px;" src="http://yannick.michelat.free.fr/grandportfolio.gif" />
            </div>
        </div>
        <div class="row hline"></div>
        <div class="row">
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-01.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-02.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-03.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-04.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-05.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-06.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-07.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-08.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-09.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-10.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-11.jpg" alt="" class="img-responsive"></a></div>
            <div class="col-xs-6 col-sm-4 col-md-2"> <a href="#" class="thumbnail"> <img src="http://yannick.michelat.free.fr/vign__CalanquesConseil-12.jpg" alt="" class="img-responsive"></a></div>
        </div>
        <div class="row hline"></div>
    </div>
    </body>
    </html>

  • Why can I not get the normal firefox start page instead of the "yourall-in-one page I currently have

    why can I not get the normal firefox start page I had with my old computer (operating XP) instead of the "your all-in-one page" I have now I have moved onto windows 7

    I have looked as suggested under the Firefox tab but find the following listed as my homepage
    http://uk.foxstart.com/?rls=en:uk:zp
    Have I actually installed firefox program/start page or have installes something else?

Maybe you are looking for

  • How to handle Responce in FILE to RFC Scenario

    Hi All, In file to RFC[sync] scenario... Sender side we are using FTP server. Many folders are there .Data is located in folder1 . File adapter picked the data and forwarded it to XI. RFC adapter processes the data.If RFc adapter sends responce , how

  • 1/8 of a beat off??? when recording audio and click??? HELP

    Okay so I upgraded to Logic Studio and I'm having this problem that basically has crushed my work flow... Here is the problem: When I record new audio from my FirePod in to Logic Studio the recorded audio is approx. and 1/8 of a beat off??? It is rea

  • Help with importing a backup-playlists

    I did a full backup onto CD's and told it to backup everything but when I imported the CD's onto the new computer the playlists didn't load!! Do I try importing again?? Where are they? I really don't want to recreate them all again and the old comput

  • I cant sync my photos!!!!!!!!!

    whenever i try to sync my photos i get an error message that says i dont have enough access privileges. Can some one help me?

  • AP 1300 Bridge mode routing!!!!!!!!!!!!!!!

    Hi there, I have two 1300 AP's one configured as a bridge mode other as a non root bridge. Right now i configured for one subnet and it works. Now i have to add one more subnet in my network, for that do i have to configure SSID? My topology is kind