package com.web.test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
public class WebTest
{
public static void main(String[] args) throws IOException
{
//test1();
//test2();
test3();
//test4();
}
public static void test1() throws IOException
{
URL url = new URL("http://lavasoft.blog.51cto.com/attachment/200811/200811271227767778082.jpg");
// 获得此URL的内容。
Object obj= url.getContent();
System.out.println(obj.getClass().getName());
}
public static void test2() throws IOException
{
URL url= new URL("http://quote.eastmoney.com/sh600007.html?StockCode=600007");
URLConnection uc=url.openConnection();
InputStream is=uc.getInputStream();
int c;
while((c=is.read())!=-1){
System.out.println(c);
}
is.close();
}
public static void test3() throws IOException
{
URL url= new URL("http://quote.futures.hexun.com/EmbChart.aspx?code=CF1205&market=3");
Reader reader = new InputStreamReader(new BufferedInputStream(url.openStream()));
int c;
while((c=reader.read())!=-1){
System.out.print((char)c);
}
reader.close();
}
//根据网络上的图片地址,将图片下载到本地
public static void test4() throws IOException
{
File file=new File("E:/pic/1002.jpg");
OutputStream out;
URL url= new URL("http://hqpick.eastmoney.com/em_quote2007/PictureK.aspx?StockCode=000001&StockMarket=1&StockStyle=1&StockLayer=2&StockCurve=9");
InputStream is=url.openStream();
file.createNewFile();
out=new FileOutputStream(file);
int c;
while((c=is.read())!=-1){
//System.out.print((char)c);
out.write(c);
}
is.close();
out.close();
System.out.println("图片保存成功!");
}
}
分享到:
相关推荐
HtmlAgilityPack 解析html,很方便很强大。
nodejs 解析html根据标签提取需要合并的js、css,并且更新html # 简介 > 站点页面上js、css外链过多会导致网页的加载速度过慢,通过合并页面的js、css成一个文件,减少http的开销。 读取config.json,解析html根据 ...
支持用XPath来解析HTML。这个意义不小,为什么呢?因为对于页面上的元素的xpath某些强大的浏览器能够直接获取得到,并不需要手动写。节约了大半写正则表达式的时间,当然正则表达式有时候在进一步获取的时候还需要写...
jsoup解析html网页的api
PHP解析HTML代码库:包含解析资源库。和demo。
解析Html 在线地址,通过获取在线地址的html文本文件
用于解析html的java开源工具,很有用
使用java编程来解析HTML文档,使大家更容易了解怎么用Java编程去解析HTML文档
Qt webkit简单使用 抓取html上的某些元素。Qt webkit简单使用 抓取html上的某些元素。
用c++解析HTML的例子。当然例子不是很多,就一个,主要解析HTML中的URL。其他的功能也可以自己扩展。
用于解析HTML DOM的PHP组件,解析起来非常方便
android 解析html (htmlParser)库和源码 因为一个项目需要解析一个网站上的新闻,所以找到了htmlParser这个开源的项目,删除了一些不需要的包,使其可以在android上用。 有两个工程,myhtml是库,要把它包含到...
方便快速解析html标记内容 。
详细解析HTML语言,特别适合初学者和想提高者。
利用asi框架解析html网页,可以截取任何网页的重要字段,显示在ui控件中!
用Jsoup解析html的所有jar包!
浏览器不解析HTML代码,访问网页直接显示HTML代码,而不是将HTML代码解析出来形成网页. 怎么解决.zip
使用Jsoup解析html网页,包含jsoup.jar \ api.chm \ 代码
解析HTML一些比较好的网站,在公司实习的时候收集,吐血推荐,有需要的可以下一下
python解析html的几种方法,lxml,xpath,htmlparser,SGMLParser等操作