运用正则表达式等方法,输出一个网页的所有手机号
package org.reg;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ex3 {
public static void main(String[] args) throws IOException {
String u = "http://www.beiyouedu.com/a/aboout/contact/";
String html = Jsoup.connect(u).get().toString();
Pattern p = Pattern.compile("1\\d{10}");
Matcher m = p.matcher(html);
Set<String> set = new HashSet<>();
while (m.find()) {
set.add(m.group());
}
System.out.println(set);
}
}
结果如图所示:
|