jsoup爬取某网站安全数据
jsoup爬取某网站安全数据
package com.vfsd.net; import java.io.IOException; import java.sql.SQLException; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import com.vfsd.dao.ManageMySQL; /** * Servlet implementation class GetURL13 */ @WebServlet("/GetURL13") public class GetURL13 extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public GetURL13() { super(); // TODO Auto-generated constructor stub } private String message; @Override public void init() throws ServletException { message = "Hello world, this message is from servlet!"; System.out.println("------"+message); try { ManageMySQL.getConnection(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //response.getWriter().append("Served at: ").append(request.getContextPath()); String agent1 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; int pageNum=1; int pageSize=10; //for(pageNum=1;pageNum<101;pageNum++) for(pageNum=1;pageNum<924;pageNum++) { try { int page1= (pageNum-1)*pageSize; Map<Integer,String> map1 = ManageMySQL.getNewsLinkInTable(page1,pageSize,"data_bjszfhcxjswyh"); for(Integer key : map1.keySet()) { System.out.println(key+" "+map1.get(key)); String news_link = map1.get(key); String context1=""; String source1=""; String publishDate = ""; //String context1 = getContentByURL(news_link).replace(" ", ""); if(!news_link.contains("void")) { if(news_link.endsWith("html")) { Document documentRoot = Jsoup.connect(news_link).userAgent(agent1).get(); Elements elements2 = documentRoot.select("#content_list"); //Elements elements2_1 = documentRoot.select("div.div_right"); if(elements2.size()==1) { Element div_ele = elements2.get(0); context1 = div_ele.text(); ManageMySQL.updateContextAndPublishDate2(key, context1.replace("‘", "").replace("\"", ""),source1,publishDate,"data_bjszfhcxjswyh"); } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
相关推荐
lzxy 2019-08-27
xiluoenm 2013-05-20
87193155 2011-09-23
XSxing 2019-06-30
wxcmdn 2019-06-28
努力的zhiyi 2015-07-13
某先生 2019-06-26
Chiclaim 2019-06-25
Danielmumu 2013-01-06
wangnan0 2012-03-15
andyhu00 2011-04-07
Jym 2013-08-28
lanyanai 2012-06-01
lanyanai 2012-02-22
编程爱好者联盟 2017-02-10
编程爱好者联盟 2016-12-20
编程爱好者联盟 2016-12-12