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

版权声明: https://blog.csdn.net/xcxzzx01/article/details/80556710

如下:

/**
	 * 获取最新的公告信息
	 * @return
	 * @throws IOException
	 */
	public static List<String> stockNotice() throws IOException {
		
		List<String> list = new ArrayList<String>();
		
		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<Element> 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<String> 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();
	}
	

没有更多推荐了,返回首页