怎样用java调用IE,然后再得到网页的源代码。 按照需求,必须先用Runtime.exec()方法调用IE打开一个网页,然后再想办法,得到这个网页的源代码。最好不要监控80端口。请给出程序代码,运行通过后立刻给分。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 既然用了Runtime.exec()就和JAVA 没社么关系了 研究下IE的参数吧 IE更不懂了,只要能得到源代码就行,这个到底能不能实现啊?要让java程序得到源代码。 Process process = Runtime.getRuntime().exec("cmd.exe /c start http://www.csdn.net");如果是本地html文件: try{ Process process = Runtime.getRuntime().exec("cmd.exe /c start Noname.html"); }catch(Exception e){e.printStackTrace();} 关键是,在IE里打开这个网页后,怎么样在JAVA里得到这个网页的源代码。wacky1020()结贴时再给你分啊,现在不知道怎么加。 public class IEExecuter implements HyperLinkExecutable { jet.util.TempFile tempFile = new jet.util.TempFile("","~url","url"); public String execute(java.awt.Component comp, String displayValue, String url) { if(url == null || url.length() == 0) return null; Runtime runtime; String filename; runtime = Runtime.getRuntime(); try{ if ( jet.util.SystemTools.isWinNT ) // check Windows NT serial in the future { File f = tempFile.createTempFile(); FileOutputStream fout = new FileOutputStream(f); PrintWriter dout = new PrintWriter(fout); dout.println("[InternetShortcut]"); dout.println("URL=" + url); dout.println("Modified=F0DB6E5C9293BE0179"); dout.close(); fout.close(); Process p = runtime.exec("cmd /c start " + f.getAbsolutePath()); p.waitFor(); synchronized(this) { try{ wait(3000); }catch(Exception e){ } } f.delete(); } else { runtime.exec("start " + url); } } catch(Exception e) { JDebug.WARNING(e); return e.getMessage(); } return null; } } 那就再帮我找找啊,谢谢了。Runtime().exec()后只得到一个Process不知道,用Runtime().exec()调用IE打开网页后,到底能不能得到网页的源代码。也许这条路行不通呢。 Process process = Runtime.getRuntime().exec(...);process.getInputStream()不知道这个InputStream会不会有效果???我想你可以使用Socket直接获得指定网页的源代码, 然后"假装"是通过打开IE获得的网页代码... 不是吧~读取网页源代码用得着这么费事吗~用HttpClient就可以了呀~public static void testClient(){ HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://www.163.com"); try{ int status = client.executeMethod(method); if (status == HttpStatus.SC_OK){ String resource = method.getResponseBodyAsString(); System.out.println(resource); }else{ System.out.println("读取网页失败Code=[" + status + "]!"); } }catch(Exception e){ e.printStackTrace(); } }注意:用commons-httpclient-3.0.1.jar的时候,另外4个也少不了commons-logging-adapters-1.1.jar,commons-logging-api-1.1.jar,commons-logging-1.1.jar,commons-codec-1.3.jar,apache官方网站都有下,用最新版就可以了。 谢谢各位的回复,但是请注意,网页必须用IE打开。我用Runtime().exec("C:/Program Files/Internet Explorer/iexplore.exe " + url)调用IE打开一个网页,然后我要这个网页的源代码。还有,我用的是jdk1.5 URL url = new URL("http://java.sun.com/index.html"); // Get the jar file InputStream is = url.openStream(); BufferedReader in = new BufferedReader( new InputStreamReader(is)); String readLine = in.readLine();; while (readLine != null) { System.out.println(readLine); readLine = in.readLine(); } 使用URL类来获得源代码就是了 如何在Java中嵌入IEhttp://blog.csdn.net/bovy/archive/2007/04/09/1557332.aspx 晕,不调用ie直接搞代码不好吗?如果必须的话你干脆先用Runtime.exec()方法打开ie,然后用url类来获取代码好了 区别一下用类名声明变量和用关键字声明的区别,有例子 水平翻转问题 数组 转 arraylist的问题 一个概率面试题 关于classpath Buffer类的介绍 如何将文件放入到内存里? 一个小问题,困扰着我~ 请大家帮忙,看看,谢谢! 紧急高分求助:如何设置对话框窗口的图标!◎在线等30分钟分不够加倍 javabean的概念 弱弱的问一个关于JAVA成员变量继承的问题
如果是本地html文件:
try{
Process process = Runtime.getRuntime().exec("cmd.exe /c start Noname.html");
}catch(Exception e){e.printStackTrace();}
wacky1020()结贴时再给你分啊,现在不知道怎么加。
{
jet.util.TempFile tempFile = new jet.util.TempFile("","~url","url");
public String execute(java.awt.Component comp, String displayValue, String url)
{
if(url == null || url.length() == 0)
return null;
Runtime runtime;
String filename;
runtime = Runtime.getRuntime();
try{
if ( jet.util.SystemTools.isWinNT ) // check Windows NT serial in the future
{
File f = tempFile.createTempFile();
FileOutputStream fout = new FileOutputStream(f);
PrintWriter dout = new PrintWriter(fout);
dout.println("[InternetShortcut]");
dout.println("URL=" + url);
dout.println("Modified=F0DB6E5C9293BE0179");
dout.close();
fout.close();
Process p = runtime.exec("cmd /c start " + f.getAbsolutePath());
p.waitFor();
synchronized(this)
{
try{
wait(3000);
}catch(Exception e){
}
}
f.delete();
}
else
{
runtime.exec("start " + url);
}
}
catch(Exception e)
{
JDebug.WARNING(e);
return e.getMessage();
}
return null;
}
}
Runtime().exec()后只得到一个Process
不知道,用Runtime().exec()调用IE打开网页后,到底能不能得到网页的源代码。也许这条路行不通呢。
process.getInputStream()不知道这个InputStream会不会有效果???我想你可以使用Socket直接获得指定网页的源代码, 然后"假装"是通过打开IE获得的网页代码...
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://www.163.com");
try{
int status = client.executeMethod(method);
if (status == HttpStatus.SC_OK){
String resource = method.getResponseBodyAsString();
System.out.println(resource);
}else{
System.out.println("读取网页失败Code=[" + status + "]!");
}
}catch(Exception e){
e.printStackTrace();
}
}注意:用commons-httpclient-3.0.1.jar的时候,另外4个也少不了commons-logging-adapters-1.1.jar,commons-logging-api-1.1.jar,commons-logging-1.1.jar,commons-codec-1.3.jar,apache官方网站都有下,用最新版就可以了。
我用Runtime().exec("C:/Program Files/Internet Explorer/iexplore.exe " + url)调用IE打开一个网页,然后我要这个网页的源代码。
还有,我用的是jdk1.5
// Get the jar file
InputStream is = url.openStream();
BufferedReader in = new BufferedReader(
new InputStreamReader(is));
String readLine = in.readLine();;
while (readLine != null) {
System.out.println(readLine);
readLine = in.readLine();
}
http://blog.csdn.net/bovy/archive/2007/04/09/1557332.aspx
如果必须的话你干脆先用Runtime.exec()方法打开ie,然后用url类来获取代码好了