使用SWT浏览器的HTML代码getter [英] HTML code getter using SWT Browser

查看:173
本文介绍了使用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:


返回一个表示当前页面内容的HTML字符串。

Returns a string with HTML that represents the content of the current page.

所以这样做的工作:

String html = browser.getText();

System.out.println(html);






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


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


请求窗口管理器以与用户点击关闭框或执行一些其他平台特定的键或鼠标组合,指示窗口应该被删除。

Requests that the window manager close the receiver in the same way it would be closed when the user clicks on the "close box" or performs some other platform specific key or mouse combination that indicates the window should be removed.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆