首页 > 编程 > Java > 正文

Java读取网页信息

2019-11-08 02:10:17
字体:
来源:转载
供稿:网友
import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.util.regex.Matcher;import java.util.regex.Pattern;public class ReadWebPage {public static void main(String[] args) { try { URL url = new URL("http://www.3158.com/view/dome/lxwm.shtml"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = ""; while ((line = br.readLine()) != null) { parse(line); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.PRintStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}private static void parse(String line) { // 获取邮箱 Pattern p = Pattern.compile("[//w[.-]]+@[//w[.-]]+//.[//w]+"); // 获取手机号码 // Pattern p = Pattern.compile("1[3,5]//d{9}"); Matcher m = p.matcher(line); while (m.find()) { System.out.println(m.group()); }}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表