代码:(次例可以拓展出你想要查询任意网站的任意信息,如邮件查询,号码归属地查询,天气查询等等)
package jxust.qiqiao.jsoupssq;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Ssqselect extends JFrame {
private JTextField showtext;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ssqselect frame = new Ssqselect();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame
*/
public Ssqselect() {
super();
getContentPane().setLayout(null);
getContentPane().setForeground(Color.LIGHT_GRAY);
setTitle("双色球中奖查询");
setName("ssqframe");
setBounds(100, 100, 318, 173);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
showtext = new JTextField();
showtext.setForeground(Color.RED);
showtext.setMargin(new Insets(1, 1, 1, 1));
showtext.setBorder(new LineBorder(Color.BLACK, 1, false));
showtext.setBounds(81, 25, 188, 24);
showtext.setEditable(false);
getContentPane().add(showtext);
final JLabel zjnumber = new JLabel();
zjnumber.setForeground(Color.BLACK);
zjnumber.setText("中奖号:");
zjnumber.setBounds(30, 28, 66, 18);
getContentPane().add(zjnumber);
final JButton button = new JButton();
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(final MouseEvent arg0) {
Document doc = null;
try {
doc = Jsoup.connect("http://kaijiang.500wan.com/").get();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "网络连接不上!", "消 息",
JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
}
Element link = doc.select("tr#ssq>td.td_kjhm01>script").first();
Pattern p = Pattern.compile("[0-9]{2}");
Matcher m = p.matcher(link.html());
List<String> list = new ArrayList<String>();
while (m.find()) {
list.add(m.group());
}
showtext.setText("");
showtext.setText(list.get(0) + " " + list.get(1) + " "
+ list.get(2) + " " + list.get(3) + " " + list.get(4)
+ " " + list.get(5)+" | "+list.get(6));
}
});
button.setText("查询");
button.setBounds(99, 66, 106, 28);
getContentPane().add(button);
}
}