首页 > 编程语言 > 详细

JAVA爬虫抓取页面的URL数据

时间:2019-09-24 13:32:52      阅读:185      评论:0      收藏:0      [点我收藏+]



在互联网发达的今天,程序员往往开发的过程中需要一些稳定的网站数据.这个时候往往有些接口数据会收费,为了方便开发.程序员会使用爬虫技术抓取数据.爬虫往往分几种:网页UR.L抓取,
根据接口抓取等等.下面介绍是根据URL抓取相应数据


1
//抓取森林防火最新页面的URL 2 public void getSlhz(){ 3 String strURL="http://wwww.forestry.gov.cn/Common/index/3563.html"; 4 URL url; 5 6 try{ 7 url = new URL(strURL); 8 HttpURLConnection httpConn=(HttpURLConnection)url.openConnection(); 9 InputStreamReader input=new InputStreamReader(httpConn.getInputStream(),"utf-8"); 10 11 BufferedReader buf= new BufferedReader(input); 12 13 String line=""; 14 StringBuilder conf=new StringBuilder(); 15 while((line=buf.readLine()))!=null){ 16 conf.append(line); 17 } 18 String buf=conf.toString(); 19 int beginIx=buf.indexOf("<ul> <li class=\"cl\"><a href=\"">); 20 int endIx=buf.indexOf("/" title=\"\""); 21 String result=buf.substring(beginIx,endIx); 22 String resl="http://www.forestry.gov.cn"+result.split("href=\"")[1]; 23 24 System.out.println(resl); 25 }catch(Exception e){ 26 e.printStackTrace(); 27 28 } 29 30 }

 

JAVA爬虫抓取页面的URL数据

原文:https://www.cnblogs.com/ComputerVip/p/11577214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!