本文测试的是网易的地址 你可以自行测试 import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; import java.util.regex.Matcher; import java.util.regex.Pattern; public class NetPaChong { /** * 正则表达式 写网络爬虫 * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String text=getContent("http://www.163.com"); System.out.println(text.length()); Pattern p=Pattern.compile("href="([\w\s./:]+?)""); Matcher m=p.matcher(text); while(m.find()){ System.out.println(m.group()); } } public static String getContent(String strUrl){ StringBuffer sb=new StringBuffer(); try { URL url=new URL(strUrl); BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream())); String temp=""; while((temp=br.readLine())!=null){ sb.append(temp); } } catch (Exception e) { e.printStackTrace(); } return sb.toString(); } }