Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)

To get selected HTML on the loaded web page use the Browser.getSelectedHTML() method as described in the example below:(要在加载的网页上获取选定的HTML,请使用Browser.getSelectedHTML()方法,如以下示例中所述:)


import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

 * The example demonstrates how to get selected HTML
 * on the loaded web page.
public class GetSelectedHTMLSample {
    public static void main(String[] args) {
        final Browser browser = new Browser();
        final BrowserView view = new BrowserView(browser);

        JButton button = new JButton("Get Selected HTML");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String html = browser.getSelectedHTML();
                        html, "Selected HTML", JOptionPane.PLAIN_MESSAGE);

        JFrame frame = new JFrame();
        frame.add(button, BorderLayout.NORTH);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);