抓取沪市上市公司公告、过滤公告内容

如下:

/**
	 * 获取最新的公告信息
	 * @return
	 * @throws IOException
	 */
	public static List stockNotice() throws IOException {
		
		List list = new ArrayList();
		
		String url = "http://www.sse.com.cn/disclosure/listedinfo/announcement/s_docdatesort_desc_2016openpdf.htm";
		Document doc = Jsoup
				.connect(url)
				.userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)")
				.timeout(5000).get();
		
		Elements dds = doc.getElementsByTag("dd");
		
		Iterator iterator = dds.iterator();
		
		while(iterator.hasNext()){
			Element element = iterator.next();
			String date = element.getElementsByTag("span").get(0).html();
			String content = element.getElementsByTag("em").get(0).getElementsByTag("a").html();
			list.add(date + " ## " + content);
		}
		
		return list;
	}
	
	/**
	 * 过滤公告信息
	 * @return
	 */
	public static String filterNotice(List list){
		StringBuffer str = new StringBuffer();
		
		String[] filters = new String[]{
			"增发","增持","合作","定增","重组","合同","增长","预增"
		};
		
		for(String s : list){
			boolean flag = false;
			//是否包含某个关键字
			for(String s0 : filters){
				if(s.contains(s0)){
					flag = true;
					break;
				}
			}
			if(flag){
				str.append(s + "\n");
				flag = false;
			}
			
		}

		return str.toString();
	}
	

你可能感兴趣的:(通用网络技术)