How to get HTML from the browser in SWT after setting the URL

非 Y 不嫁゛ 提交于 2019-12-06 04:15:51

You could force SWT to use another browser engine (if available) to work around this bug.

For example

Browser browser = new Browser( parent, SWT.WEBKIT );

or

Browser browser = new Browser( parent, SWT.MOZILLA );

The source of the problem, however, is that you are trying to obtain the page source before it was fully loaded. If there wasn't the bug that you mentioned, SWT would still return an empty string.

The fix is to listen for the page to complete loading and only then ask the browser to return the page source. For example:

Browser browser = new Browser( shell, SWT.NONE );
browser.addProgressListener( new ProgressAdapter() {
  @Override
  public void completed( ProgressEvent event ) {
    String text = browser.getText();
    // here, text will contain the full page source
  }
} );
browser.setUrl( "http://eclipse.org" );         
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!