爬网程序_帮助Web爬网程序有效地爬网您的门户网站和网站

爬网程序

存档日期:2019年5月16日 | 首次发布:2007年5月8日

网站管理员以及搜索技术提供商都面临着寻找或协助查找高质量信息的挑战。 使用新的Sitemaps 0.90协议,网站管理员可以通过以更优化的方式向爬网程序提供有关其网站的信息来支持此工作。 通过该协议,可以精确指定要爬网的内容,信息更新的频率以及相对于特定站点的重要性。

本文概述了Sitemaps 0.90协议,还告诉您如何使用IBM®WebSphere®Portal版本6(以下称为WebSphere Portal)来生成和部署这样的站点地图。 您应该对XML和WebSphere Portal管理有很好的了解,以完全了解您正在阅读的内容。

此内容不再被更新或维护。 全文以PDF格式“按原样”提供。 随着技术的飞速发展,某些内容,步骤或插图可能已更改。

翻译自: https://www.ibm.com/developerworks/xml/library/x-sitemaps/index.html

爬网程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; public class GetNetHtml { public static String createhttpClient(String url, String param) { HttpClient client = new HttpClient(); String response = null; String keyword = null; PostMethod postMethod = new PostMethod(url); // try { // if (param != null) // keyword = new String(param.getBytes("gb2312"), "ISO-8859-1"); // } catch (UnsupportedEncodingException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // NameValuePair[] data = { new NameValuePair("keyword", keyword) }; // // 将表单的值放入postMethod中 // postMethod.setRequestBody(data); // 以上部分是带参数抓取,我自己把它注销了.大家可以把注销消掉研究下 try { int statusCode = client.executeMethod(postMethod); response = new String(postMethod.getResponseBodyAsString() .getBytes("ISO-8859-1"), "gb2312");//这里要注意下 gb2312要和你抓取页的编码要一样 String p = response.replaceAll("\\&[a-zA-Z]{1,10};", "") .replaceAll("<[^>]*>", "");//去掉页中带有html语言的标签 System.out.println(p); } catch (Exception e) { e.printStackTrace(); } return response; } // 第二种方法 // 这种方法是JAVA自带的URL来抓取网站内容 public String getPageContent(String strUrl, String strPostRequest, int maxLength) { // 读取结果页 StringBuffer buffer = new StringBuffer(); System.setProperty("sun.net.client.defaultConnectTimeout", "5000"); System.setProperty("sun.net.client.defaultReadTimeout", "5000"); try { URL newUrl = new URL(strUrl); HttpURLConnection hConnect = (HttpURLConnection) newUrl .openConnection(); // POST方式的额外数据 if (strPostRequest.length() > 0) { hConnect.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(hConnect .getOutputStream()); out.write(strPostRequest); out.flush(); out.close(); } /*部分删节,请下载细看!!*/ public static void main(String[] args) { String url = "http://www.liuzm.com"; String keyword = "刘志猛博客"; GetNetHtml p = new GetNetHtml(); String response = p.createhttpClient(url, keyword); // 第一种方法 // p.getPageContent(url, "post", 100500);//第二种方法 } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值