Python 爬取 北京市政府首都之窗信件列表-[信息展示]
Posted 初等变换不改变矩阵的秩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 爬取 北京市政府首都之窗信件列表-[信息展示]相关的知识,希望对你有一定的参考价值。
日期:2020.01.25
博客期:133
星期六
【代码说明,如果要使用此页代码,必须在本博客页面评论区给予说明】
//博客总体说明
1、准备工作
2、爬取工作
3、数据处理
4、信息展示(本期博客)
大年初一,先给大家说声“过年好”!嗯~说说今天写的部分,因为今天过大年嘛,也没有写什么特别难的东西!就是把上一回博客的内容进行整理,然后根据ECharts的接口进行数据可视化的展示!
下面是项目的目录结构:
嗯!老师说基本的页面是按照我的那个老模板来做的,这样比较省力气!
Java部分:
com.dblink包(连接数据库的包),参考博客:https://www.cnblogs.com/onepersonwholive/p/12168785.html
com.servlet包
1 package com.servlet; 2 3 import java.io.IOException; 4 import java.sql.SQLException; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.ServletOutputStream; 9 import javax.servlet.annotation.WebServlet; 10 import javax.servlet.http.HttpServlet; 11 import javax.servlet.http.HttpServletRequest; 12 import javax.servlet.http.HttpServletResponse; 13 14 import org.json.JSONArray; 15 import org.json.JSONObject; 16 17 import com.dblink.basic.utils.SqlUtils; 18 import com.dblink.basic.utils.sqlKind.MySql_s; 19 import com.dblink.basic.utils.user.UserInfo; 20 import com.dblink.bean.BeanGroup; 21 import com.dblink.sql.DBLink; 22 23 @SuppressWarnings("unused") 24 public class ServletForEveryYear extends HttpServlet{ 25 /** 26 * 27 */ 28 private static final long serialVersionUID = 1L; 29 //----------------------------------------------------------------------// 30 public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 31 { 32 request.setCharacterEncoding("utf-8"); 33 response.setCharacterEncoding("utf-8"); 34 response.setContentType("application/json"); 35 response.setHeader("Cache-Control", "no-cache"); 36 response.setHeader("Pragma", "no-cache"); 37 38 JSONObject jsonobject = new JSONObject(); 39 40 JSONArray dt = new JSONArray(); 41 JSONArray num = new JSONArray(); 42 43 DBLink dbLink = new DBLink(new SqlUtils(new MySql_s("edu"),new UserInfo("root","123456"))); 44 BeanGroup bg = null; 45 try { 46 bg = dbLink.getSelect("Select * From yeardata").beans; 47 int leng = bg.size(); 48 for(int i=0;i<leng;++i) 49 { 50 dt.put(bg.get(i).get(0)); 51 num.put(bg.get(i).get(1)); 52 } 53 } catch (SQLException e) { 54 // Do Nothing ... 55 } 56 dbLink.free(); 57 jsonobject.put("YEAR",dt); 58 jsonobject.put("NUM",num); 59 60 ServletOutputStream os = response.getOutputStream(); 61 os.write(jsonobject.toString().getBytes()); 62 os.flush(); 63 os.close(); 64 } 65 //---------------------------------------------------------------------------------// 66 }
1 package com.servlet; 2 3 import java.io.IOException; 4 import java.sql.SQLException; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.ServletOutputStream; 9 import javax.servlet.annotation.WebServlet; 10 import javax.servlet.http.HttpServlet; 11 import javax.servlet.http.HttpServletRequest; 12 import javax.servlet.http.HttpServletResponse; 13 14 import org.json.JSONArray; 15 import org.json.JSONObject; 16 17 import com.dblink.basic.utils.SqlUtils; 18 import com.dblink.basic.utils.sqlKind.MySql_s; 19 import com.dblink.basic.utils.user.UserInfo; 20 import com.dblink.bean.BeanGroup; 21 import com.dblink.sql.DBLink; 22 23 @SuppressWarnings("unused") 24 public class ServletForResponser extends HttpServlet{ 25 /** 26 * 27 */ 28 private static final long serialVersionUID = 1L; 29 //----------------------------------------------------------------------// 30 public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 31 { 32 request.setCharacterEncoding("utf-8"); 33 response.setCharacterEncoding("utf-8"); 34 response.setContentType("application/json"); 35 response.setHeader("Cache-Control", "no-cache"); 36 response.setHeader("Pragma", "no-cache"); 37 38 JSONObject jsonobject = new JSONObject(); 39 40 JSONArray dt = new JSONArray(); 41 JSONArray num = new JSONArray(); 42 43 DBLink dbLink = new DBLink(new SqlUtils(new MySql_s("edu"),new UserInfo("root","123456"))); 44 BeanGroup bg = null; 45 try { 46 bg = dbLink.getSelect("Select * From responserdata").beans; 47 int leng = bg.size(); 48 for(int i=0;i<5;++i) 49 { 50 dt.put(bg.get(i).get(0)); 51 num.put(bg.get(i).get(1)); 52 } 53 } catch (SQLException e) { 54 // Do Nothing ... 55 } 56 dbLink.free(); 57 jsonobject.put("RESPONSER",dt); 58 jsonobject.put("NUM",num); 59 60 ServletOutputStream os = response.getOutputStream(); 61 os.write(jsonobject.toString().getBytes()); 62 os.flush(); 63 os.close(); 64 } 65 //---------------------------------------------------------------------------------// 66 }
1 package com.servlet; 2 3 import java.io.IOException; 4 import java.sql.SQLException; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.ServletOutputStream; 9 import javax.servlet.annotation.WebServlet; 10 import javax.servlet.http.HttpServlet; 11 import javax.servlet.http.HttpServletRequest; 12 import javax.servlet.http.HttpServletResponse; 13 14 import org.json.JSONArray; 15 import org.json.JSONObject; 16 17 import com.dblink.basic.utils.SqlUtils; 18 import com.dblink.basic.utils.sqlKind.MySql_s; 19 import com.dblink.basic.utils.user.UserInfo; 20 import com.dblink.bean.BeanGroup; 21 import com.dblink.sql.DBLink; 22 23 @SuppressWarnings("unused") 24 public class ServletForKindData extends HttpServlet{ 25 /** 26 * 27 */ 28 private static final long serialVersionUID = 1L; 29 //----------------------------------------------------------------------// 30 public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 31 { 32 request.setCharacterEncoding("utf-8"); 33 response.setCharacterEncoding("utf-8"); 34 response.setContentType("application/json"); 35 response.setHeader("Cache-Control", "no-cache"); 36 response.setHeader("Pragma", "no-cache"); 37 38 JSONObject jsonobject = new JSONObject(); 39 40 JSONArray kind = new JSONArray(); 41 JSONArray num = new JSONArray(); 42 JSONArray jsonA = new JSONArray(); 43 44 DBLink dbLink = new DBLink(new SqlUtils(new MySql_s("edu"),new UserInfo("root","123456"))); 45 BeanGroup bg = null; 46 try { 47 bg = dbLink.getSelect("Select * From kinddata").beans; 48 int leng = bg.size(); 49 for(int i=0;i<leng;++i) 50 { 51 JSONObject json = new JSONObject(); 52 json.put("name",bg.get(i).get(0)); 53 json.put("value",bg.get(i).get(1)); 54 kind.put(bg.get(i).get(0)); 55 num.put(bg.get(i).get(1)); 56 jsonA.put(json); 57 } 58 } catch (SQLException e) { 59 // Do Nothing ... 60 } 61 dbLink.free(); 62 jsonobject.put("KIND",kind); 63 jsonobject.put("NUM",num); 64 jsonobject.put("DATA",jsonA); 65 66 ServletOutputStream os = response.getOutputStream(); 67 os.write(jsonobject.toString().getBytes()); 68 os.flush(); 69 os.close(); 70 } 71 //---------------------------------------------------------------------------------// 72 }
JSP + JS 部分:
web.xml部分(配置servlet)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0"> 3 <display-name>BeiJingEmailPostAndDeal</display-name> 4 <servlet> 5 <description>This is the description of my J2EE component</description> 6 <display-name>This is the display name of my J2EE component</display-name> 7 <servlet-name>ServletForEveryYear</servlet-name> 8 <servlet-class>com.servlet.ServletForEveryYear</servlet-class> 9 </servlet> 10 <servlet-mapping> 11 <servlet-name>ServletForEveryYear</servlet-name> 12 <url-pattern>/com/servlet/ServletForEveryYear</url-pattern> 13 </servlet-mapping> 14 <servlet> 15 <description>This is the description of my J2EE component</description> 16 <display-name>This is the display name of my J2EE component</display-name> 17 <servlet-name>ServletForResponser</servlet-name> 18 <servlet-class>com.servlet.ServletForResponser</servlet-class> 19 </servlet> 20 <servlet-mapping> 21 <servlet-name>ServletForResponser</servlet-name> 22 <url-pattern>/com/servlet/ServletForResponser</url-pattern> 23 </servlet-mapping> 24 <servlet> 25 <description>This is the description of my J2EE component</description> 26 <display-name>This is the display name of my J2EE component</display-name> 27 <servlet-name>ServletForKindData</servlet-name> 28 <servlet-class>com.servlet.ServletForKindData</servlet-class> 29 </servlet> 30 <servlet-mapping> 31 <servlet-name>ServletForKindData</servlet-name> 32 <url-pattern>/com/servlet/ServletForKindData</url-pattern> 33 </servlet-mapping> 34 <welcome-file-list> 35 <welcome-file>index.html</welcome-file> 36 <welcome-file>index.htm</welcome-file> 37 <welcome-file>index.jsp</welcome-file> 38 <welcome-file>default.html</welcome-file> 39 <welcome-file>default.htm</welcome-file> 40 <welcome-file>default.jsp</welcome-file> 41 </welcome-file-list> 42 </web-app>
jspFiles
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html> 4 <html><!-- xmlns="http://www.w3.org/1999/xhtml" --> 5 <head> 6 <!--<meta charset="utf-8" />--> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"/> 8 <title>北京市人民政府信件数据分析</title> 9 <!-- BOOTSTRAP STYLES--> 10 <link href="../assets/css/bootstrap.css" rel="stylesheet" /> 11 <!-- FONTAWESOME STYLES--> 12 <link href="../assets/css/font-awesome.css" rel="stylesheet" /> 13 <!-- CUSTOM STYLES--> 14 <link href="../assets/css/custom.css" rel="stylesheet" /> 15 <!-- PERSONAL FONTS--> 16 <link href=\'../cssFiles/basic.css\' rel=\'stylesheet\' type=\'text/css\' /> 17 <!-- GOOGLE FONTS--> 18 <link href=\'http://fonts.googleapis.com/css?family=Open+Sans\' rel=\'stylesheet\' type=\'text/css\' /> 19 </head> 20 <script src="../jsFiles/jquery/jquery-3.4.1.min.js" charset="utf-8"></script> 21 <script src="../jsFiles/echarts/echarts.min.js" charset="utf-8"></script> 22 <script src="../jsFiles/basic.js" charset="utf-8"></script> 23 <script src="../jsFiles/part1.js" charset="utf-8"></script> 24 <script src="../jsFiles/part2.js" charset="utf-8"></script> 25 <script src="../jsFiles/part3.js" charset="utf-8"></script> 26 <body> 27 <div id="wrapper"> 28 <div class="navbar navbar-inverse navbar-fixed-top"> 29 <div class="adjust-nav"> 30 <div class="navbar-header"> 31 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse"> 32 <span class="icon-bar"></span> 33 <span class="icon-bar"></span> 34 <span class="icon-bar"></span> 35 Python 爬取 北京市政府首都之窗信件列表-[Scrapy框架](2020年寒假小目标04)Python 爬取 北京市政府首都之窗信件列表-[后续补充]
[Python]爬取首都之窗百姓信件网址id python 2020.2.13