50,530
社区成员
发帖
与我相关
我的任务
分享
int j = 0;
for (int i = 11; i < 13; i++) {
String urlString = "http://mall.jumei.com/products/0-19-0-11-" + i+
".html";
URL url = new URL(urlString);
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
byte[] bs = new byte[1024];
int len;
StringBuffer sb = new StringBuffer();
while ((len = is.read(bs)) != -1) {
sb.append(new String(bs, 0, len));
}
is.close();
String content = sb.toString();
Matcher m =
Pattern.compile("(?s)<div class=\"num_warp_list_name\">(.*?)</div>.*?<span style=\"font-size:18px; font-weight:bolder; color:#ed145b;\">(.*?)</span").matcher(content);
while (m.find()) {
j++;
System.out.println(m.group(1).replaceAll("\\s",
"").replaceAll("<a.*?>(.*?)</a>",
"$1")+"--->第"+j+"个------->"+m.group(2).replace("¥", "¥"));
}
}