如何获得html文件中 每一段的文本内容 apache tags scrape看一下源代码吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.net.*;public class king{public king(){try{URL url=new URL("http://www.csdn.net");BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));String i;while((i=in.readLine())!=null){System.out.println(i);}}catch(IOException e){}}public static void main(String[] agag){new king();}} 现在网页中用<p></p>的太少了,你自己找一个带标记的网页试。import java.net.*;import java.io.*;public class Test { URL url; InputStream in; String html = ""; String temp; int p1=0,p2=0; public Test(){ try { url = new URL("http://www.XXXXX.com"); } catch (MalformedURLException ex) { } try { in = url.openStream(); } catch (IOException ex1) { } } public void Read(){ BufferedReader r = null; try { r = new BufferedReader(new InputStreamReader(url.openStream())); } catch (IOException ex) { } try { String str; while ( (str = r.readLine()) != null) { html = html.concat(str); } while(p2+1<=html.lastIndexOf("</p>")){ p1 = html.indexOf("<p>",p2); p2 = html.indexOf("</p>",p2+1); temp = html.substring(p1+3,p2); System.out.println(temp); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException ignored) { ignored.printStackTrace(); } } public static void main(String[] args) { Test test = new Test(); test.Read(); }}<------ 树欲静而风不止 ------> 自己当字符串搜索<p>来处理了,呵呵,多谢大家的参与; 一道Java的算法题 java如何在内存中模拟树型结构?有哪几种常用方法? 面试题求教:写一个二叉树插入算法,什么情况下二叉树性能最差? 新人求教 :一个简单的继承问题! 怎样整合数据库对用户做验证? 应当简单吧?这些包在哪个文件夹下? 我是JAVA初学者希望大家帮助一下 java中有类似C中的select(...)函数吗? 请问intern的作用是什么? Stateful session bean的一个小问题! 我是菜鸟,学习JAVA有“钱图“么? 初学JAVA 请教各位高手
import java.net.*;
public class king{
public king(){
try{
URL url=new URL("http://www.csdn.net");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String i;
while((i=in.readLine())!=null){
System.out.println(i);
}
}catch(IOException e){
}
}public static void main(String[] agag){
new king();
}
}
import java.io.*;public class Test {
URL url;
InputStream in;
String html = "";
String temp;
int p1=0,p2=0; public Test(){
try {
url = new URL("http://www.XXXXX.com");
}
catch (MalformedURLException ex) {
}
try {
in = url.openStream();
}
catch (IOException ex1) {
}
} public void Read(){
BufferedReader r = null;
try {
r = new BufferedReader(new InputStreamReader(url.openStream()));
}
catch (IOException ex) {
}
try {
String str;
while ( (str = r.readLine()) != null) {
html = html.concat(str);
}
while(p2+1<=html.lastIndexOf("</p>")){
p1 = html.indexOf("<p>",p2);
p2 = html.indexOf("</p>",p2+1);
temp = html.substring(p1+3,p2);
System.out.println(temp);
}
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException ignored) {
ignored.printStackTrace();
}
} public static void main(String[] args) {
Test test = new Test();
test.Read();
}
}<------ 树欲静而风不止 ------>