本文介绍了使用SWT浏览器的HTML代码getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用SWT Broser将HTML页面代码转换为String?

How I can get html-page code to String using SWT Broser?

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(100, 100);


    Browser browser = new Browser(shell, SWT.NONE);
    browser.setBounds(5, 75, 100, 100);

    shell.open();
    browser.setUrl("https://google.com");

    String html = browser.getText(); //NOTHING!

    while (!shell.isDisposed()) {

        if (!display.readAndDispatch() && html == null) {

            display.sleep();
        }
    }

    display.dispose();

    Syste.out.println(html); ////NOTHING!

那么,我该怎么做html?最好的方法是在html代码获取显示窗口后关闭?

So, how I can take html? And best way, when after html-code getting the display window will close?

推荐答案

您正在搜索的方法是: a href =http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/browser/Browser.html#getText%28%29相对= nofollow> 浏览器#的getText() 。这是javadoc的重要组成部分:

The method you are searching for is: Browser#getText(). Here is the important part of the javadoc:

所以这样做的工作:

String html = browser.getText();

System.out.println(html);






对于您的第二个问题:您可以关闭shell通过调用。这是Javadoc:


For your second question: You can close the shell by calling Shell#close(). Here is the Javadoc:

这篇关于使用SWT浏览器的HTML代码getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:11
查看更多