java web页面数据抓取 博客分类: java Web数据抓取采集
程序员文章站
2024-02-22 08:54:34
...
java抓取数据后,写入本地文件
public static void main(String[] args){ URL url = null; String path = null; String filePath = null; try { url = new URL("http://publish.it168.com/2005/0915/20050915022401.shtml"); URLConnection urlCon = url.openConnection(); BufferedReader bufReader = new BufferedReader(new InputStreamReader(urlCon.getInputStream(),"gbk")); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); String dateString = formatter.format(new Date()); SimpleDateFormat formatter1 = new SimpleDateFormat("HHmmss"); String dateString1 = formatter1.format(new Date()); path = "e:/webDataGather/"+dateString; File dirFile =new File(path); if(!(dirFile.exists())) dirFile.mkdirs(); filePath = path+"/"+dateString1+".html"; BufferedWriter bufWriter = new BufferedWriter(new FileWriter(filePath)); copy(bufReader, bufWriter); bufReader.close(); bufWriter.close(); Show(filePath,"C:/Program Files/360/360se3/360SE.exe"); } catch (Exception e) { e.printStackTrace(); } } public static void copy(BufferedReader read,BufferedWriter write) throws IOException{ String str; StringBuilder dataStr = new StringBuilder(); while((str=read.readLine())!=null){ dataStr.append(str); } write.write(dataStr.toString()); Pattern p = Pattern.compile("<table>.*</table>"); Matcher m = p.matcher(dataStr.toString()); while(m.find()){ System.out.println(m.group()); write.write(m.group()); } } public static void Show(String url, String urliexplore) { try { Runtime rr = Runtime.getRuntime(); rr.exec(urliexplore + " " + url); } catch (Exception er) { } }
推荐阅读
-
java web页面数据抓取 博客分类: java Web数据抓取采集
-
使用动态代理IP让爬虫效率提高N倍 博客分类: Java 动态代理IP数据抓取数据爬虫IP被封禁换IP抓数据
-
java web开发,bean数据放在request、response还是servletcontext中? 博客分类: 技术及貌似 BeanWebJava应用服务器JVM
-
Hibernate生猛上手 博客分类: 数据库java web hibernateorm
-
让web应用轻松拥有log和数据库(DAO)支持 博客分类: JavaOracleDAOMysqlWeb java数据库webdao
-
Java URL抓取页面内容乱码问题解决办法 博客分类: java JavaOracleITeyeYahooHTML
-
Java Web工程连接MySQL数据库及Tomcat服务器页面中文乱码
-
Java Web工程连接MySQL数据库及Tomcat服务器页面中文乱码
-
谁能给我一个用java实现柱状图,饼图的例子!链接数据库的。还有就是不知道怎么显示在jsp页面上。_html/css_WEB-ITnose
-
谁能给我一个用java实现柱状图,饼图的例子!链接数据库的。还有就是不知道怎么显示在jsp页面上。_html/css_WEB-ITnose