http://mahathirtanmoy.wix.com/tanmoy-world 这是一个随机生成的网站,使用WIX编辑器,我只添加了两个句子
Hello word
OK JOB DONE。
我想在netbeans IDE输出上使用java编程显示这两句话。 Plz建议我应该为此学习什么,以及我必须遵循的过程是什么。 如果我知道如何做到这一点,以后我可以分享代码,如果有任何进一步的困难。我可以为任何HTML页面这样做吗?
答案 0 :(得分:1)
您需要使用JSoup来解析网站并返回两个句子。
答案 1 :(得分:1)
public class ReadIp{
public int getIP() throws MalformedURLException, IOException {
try
{
String ip = "";
String nextLine;
URL url = null;
URLConnection urlConn = null;
InputStreamReader inStream = null;
BufferedReader buff = null;
url = new URL("http://mahathirtanmoy.wix.com/tanmoy-world");
urlConn = url.openConnection();
inStream = new InputStreamReader(
urlConn.getInputStream());
buff = new BufferedReader(inStream);
while ((nextLine = buff.readLine()) != null) {
System.out.println(nextLine);
}}
catch(Exception ex)
{}
return 0;
}
public static void main(String[] args) throws MalformedURLException, IOException {
ReadIp rp = new ReadIp();
rp.getIP();
}
}
}
答案 2 :(得分:0)
试试这个。我用它来从http://www.whatismyip.org读取我的IP地址,它运行正常。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class ReadIp{
public void getIP() throws MalformedURLException, IOException{
String ip="";
String nextLine;
URL url = null;
URLConnection urlConn = null;
InputStreamReader inStream = null;
BufferedReader buff = null;
url = new URL("http://www.whatismyip.org" );
urlConn = url.openConnection();
inStream = new InputStreamReader(
urlConn.getInputStream());
buff= new BufferedReader(inStream);
while ((nextLine =buff.readLine()) !=null){
System.out.println(nextLine);
}
}
}