- 浏览: 777635 次
- 性别:
- 来自: 西安
文章分类
最新评论
-
mushme:
W.sl 写道大神:http://mushme.iteye.c ...
用python自动登录iteye -
W.sl:
大神:http://mushme.iteye.com/logi ...
用python自动登录iteye -
mushme:
jilong-liang 写道 public static v ...
选择一个好的驾校,用数据说话,我用python -
jilong-liang:
package sm;import java.net.URL; ...
选择一个好的驾校,用数据说话,我用python -
sunshine_bean:
非常感谢
jsvc将tomcat配置成服务
在交管局网站上,看到每月的考试信息都有工具。
想想,可以汇总下,按照考试人数排个名(群众的选择大部分时候都是有道理的)
1.数据先抓取下来
2.把数据导出到excel里
3.在excel里做个透视图,按月汇总并排序下,得到结果如下
西安西高驾校科二考场 1870 1241 1158 1095 5364
北所科目一考场 1593 1227 1088 863 4771
郊县分所蓝田县科三考试场 3887 210 343 256 4696
郊县长安科目一考场 2332 1844 15 282 4473
西安支队尚稷路科三考场 2263 764 834 567 4428
西安科目三咸阳吉祥考场 868 928 766 1488 4050
东所科目一考场 2664 300 230 159 3353
西安小型车科目三铜川考场 1424 574 557 588 3143
西安支队户县科目三考场 2107 186 343 338 2974
南所科目一考场 1397 473 511 433 2814
西安天平驾校科二考场 1457 456 890 2803
西安博安驾校科目二考场 842 313 935 417 2507
西安华津驾校科二考场 1494 120 422 291 2327
西所科目一考场 1560 262 193 208 2223
郊县阎良科目一考场 1708 226 1934
西安小型车科目三咸阳西郊考场 5 186 544 783 1518
郊县户县科目一考场 1188 247 21 33 1489
public static void trustEveryone() {
这个方法的作用是什么?
想想,可以汇总下,按照考试人数排个名(群众的选择大部分时候都是有道理的)
1.数据先抓取下来
#encoding=utf8 import urllib import urllib.request import http.cookiejar from bs4 import BeautifulSoup # 导入SQLite驱动: import sqlite3 User_Agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0' header = {} header['User-Agent'] = User_Agent vyear='201601' urlFile = urllib.request.urlopen('https://sn.122.gov.cn/publicitypage?size=20&fzjg=%E9%99%95A&page=1&tjyf='+vyear) data = urlFile.read() urlFile.close() data = data.decode('utf-8',errors='ignore') print("get page success") pre = "<div id='pagination'><span class=''>共" index1 = data.find(pre) + len(pre) index2 = data.find('条记录', index1) ebi=data[index1 : index2]; print("总条数:"+ebi) totalPage=""; if (int(data[index1 : index2]))%20>0: totalPage=str(int(int(data[index1 : index2])/20+1)) else: totalPage=str(int(int(data[index1 : index2])/20)) print("totalpage:"+totalPage); def getList(pageId): hosturl = 'https://sn.122.gov.cn/publicitypage?size=20&fzjg=%E9%99%95A&tjyf='+vyear+'&page='+pageId print("getcontent:"+hosturl); request = urllib.request.Request(hosturl, None, header) response = urllib.request.urlopen(request) htmldata = response.read() soup = BeautifulSoup(htmldata,"html.parser") trs = soup.findAll('tr') for x in range(1,len(trs)): tr = trs[x] tds = tr.findAll("td") savejiaxiao(tds[0].contents[0],tds[1].contents[0],tds[2].contents[0],tds[3].contents[0],tds[4].contents[0],tds[5].contents[0]); def savejiaxiao(t_date, t_name,t1,t2,t3,t4): conn = sqlite3.connect('jiaxiao.db') cursor = conn.cursor() # 执行一条SQL语句,创建user表: cursor.execute('create table IF NOT EXISTS kaoshi (id INTEGER PRIMARY KEY, t_date varchar(100),t_name varchar(100),t1 varchar(100),t2 varchar(100),t3 varchar(100),t4 varchar(100) )') cursor.execute('select * from kaoshi where t_date=\''+t_date+'\' and t_name=\''+t_name+'\' and t1=\''+t1+'\' and t2=\''+t2+'\' and t3=\''+t3+'\' and t4=\''+t4+'\' ') values=cursor.fetchall() if len(values) > 0:#以前就存在 print('已经存在:'+t_date+','+t_name) else: try: cursor.execute('insert into kaoshi (t_date, t_name,t1,t2,t3,t4) values(?,?,?,?,?,?)',(t_date,t_name,t1,t2,t3,t4)) print("save success."+t_date+','+t_name) except Exception as e: print('except:', e) # 关闭Cursor: cursor.close() # 提交事务: conn.commit() # 关闭Connection: conn.close() for x in range(1,int(totalPage)+1): #代表从1到totalPage+1(不包含totalPage) errorLink=[] try: getList(str(x)) except Exception as e: print('except:', e) errorLink.append(x) print("errorLink:"+str(errorLink));
2.把数据导出到excel里
# -*- coding:utf-8 -*- import xlwt # 导入SQLite驱动: import sqlite3 def export(): conn = sqlite3.connect('jiaxiao2016.db') cursor = conn.cursor() cursor.execute('select * from kaoshi') values = cursor.fetchall() i=0 book=xlwt.Workbook() sheet1=book.add_sheet('驾校') for line in values: row = sheet1.row(i) row.write(0,line[0])#id row.write(1,line[1])#title row.write(2,line[2])#link row.write(3,line[3]) row.write(4,line[4]) row.write(5,line[5]) row.write(6,line[6]) sheet1.col(1).width = 5000 i=i+1 book.save('驾校2016.xls') cursor.close() conn.commit() conn.close() export()
3.在excel里做个透视图,按月汇总并排序下,得到结果如下
西安西高驾校科二考场 1870 1241 1158 1095 5364
北所科目一考场 1593 1227 1088 863 4771
郊县分所蓝田县科三考试场 3887 210 343 256 4696
郊县长安科目一考场 2332 1844 15 282 4473
西安支队尚稷路科三考场 2263 764 834 567 4428
西安科目三咸阳吉祥考场 868 928 766 1488 4050
东所科目一考场 2664 300 230 159 3353
西安小型车科目三铜川考场 1424 574 557 588 3143
西安支队户县科目三考场 2107 186 343 338 2974
南所科目一考场 1397 473 511 433 2814
西安天平驾校科二考场 1457 456 890 2803
西安博安驾校科目二考场 842 313 935 417 2507
西安华津驾校科二考场 1494 120 422 291 2327
西所科目一考场 1560 262 193 208 2223
郊县阎良科目一考场 1708 226 1934
西安小型车科目三咸阳西郊考场 5 186 544 783 1518
郊县户县科目一考场 1188 247 21 33 1489
评论
2 楼
mushme
2016-08-11
jilong-liang 写道
public static void trustEveryone() {
这个方法的作用是什么?
1 楼
jilong-liang
2016-07-05
package sm;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.X509TrustManager;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Test {
public static void main(String[] args) throws Exception{
trustEveryone();
for (int i = 1; i <=42; i++) {
String url="https://sn.122.gov.cn/publicitypage?size="+i+"&page=7&tjyf=201601&fzjg=%E9%99%95A&fwdmgl=6003";
Document doc=Jsoup.parse(new URL(url), 3000);
//处理从页面的class=table table-stirped table-hover样式下面的li标签
Elements trs=doc.getElementsByAttributeValue("class", "table table-stirped table-hover").select("tr");
for(Element tr:trs){
String rq = tr.select("td:eq(0)").text();//日期
String kcmc = tr.select("td:eq(1)").text();//考场名称
System.out.println(kcmc);
}
}
}
public static void trustEveryone() {
try {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.X509TrustManager;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Test {
public static void main(String[] args) throws Exception{
trustEveryone();
for (int i = 1; i <=42; i++) {
String url="https://sn.122.gov.cn/publicitypage?size="+i+"&page=7&tjyf=201601&fzjg=%E9%99%95A&fwdmgl=6003";
Document doc=Jsoup.parse(new URL(url), 3000);
//处理从页面的class=table table-stirped table-hover样式下面的li标签
Elements trs=doc.getElementsByAttributeValue("class", "table table-stirped table-hover").select("tr");
for(Element tr:trs){
String rq = tr.select("td:eq(0)").text();//日期
String kcmc = tr.select("td:eq(1)").text();//考场名称
System.out.println(kcmc);
}
}
}
public static void trustEveryone() {
try {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
}
发表评论
-
useragent
2016-10-04 16:01 1866USER_AGENTS = [ "Mo ... -
整理一个python工具类
2016-09-08 16:26 1004mark一个工具类 from urllib.request ... -
scrapy抓取cnblog新闻
2016-09-08 16:00 1870tutorial/items.py:项目的items文件 t ... -
scrapy抓取dmoz内容
2016-09-07 14:18 8911.新建一个项目 scrapy startproject ... -
安装scrapy
2016-09-07 11:03 6111.使用pip安装 pip install Scrapy ... -
获取天气预报的接口
2016-07-05 16:28 962以前的几个天气预报的接口没法用了,新找了两个接口 一个接口启用 ... -
python版wobot
2016-04-19 20:49 599#-*- coding: UTF-8 -*- impor ... -
运用百度语音识别来读文字
2016-04-04 22:09 1148运用百度语音识别来读取你的本地内容 1.把本地文字传递给百度语 ... -
多线程下载cnblog新闻图片
2016-03-31 10:17 773主要处理的问题有: 1.如何防止重复下载 2.网络访问一般较慢 ... -
使用python备份搜狐博客
2016-02-24 15:17 490博客日落西山,已经是 ... -
使用python从360doc上抓取内容
2016-01-27 15:32 2084#人生苦短,我用python 在360doc上查到一篇不错的文 ... -
python连接telnet
2016-01-26 10:39 1946# -*- coding: utf-8 -*- imp ... -
获取可用的代理服务器
2016-01-26 08:27 14751.找到一个可用的代理服务器源 2.验证并找出可用的代理服务器 ... -
每日自动下载bing背景图片做桌面之python
2016-01-08 10:17 3910百度已经烂到没法用了,开始使用bing,发现bing的首页背景 ... -
python数据抓取
2015-12-28 16:28 1077经过折腾,python果然是数据抓取的利器。 火车头类的东西, ... -
用python自动登录iteye
2015-12-24 14:24 840需要beautifulsoup插件,python版本3 # ...
相关推荐
所上传的资源是python编写的驾校考题项目,内含源代码+数据库脚本+详细部署视频,另外还对过程中可能出现的问题进行了汇总,对于正在学习这方面的你是一个很好的选择,希望我所上传的资源对你有所帮助。
python毕业设计、期末大作业基于Django+mysql的驾校综合服务平台系统源码。 软件架构 软件架构说明 安装教程 将项目下载到本地 运行 .sql文件。 运行代码,浏览器查看。 介绍 python毕业设计、期末大作业基于...
驾校一点通 源码下载
驾校计算机综合管理系统介绍.doc
驾校-驾校系统-驾校系统源码-驾校管理系统-驾校管理系统java代码-驾校系统设计与实现-基于springboot的驾校系统-基于Web的驾校系统设计与实现-驾校网站-驾校网站代码-驾校平台-驾校平台代码-驾校项目-驾校项目代码-...
驾校一点通v驾校一点通驾校一点通驾校一点通驾校一点通驾校一点通驾校一点通驾校一点通驾校一点通驾校一点通驾校一点通
驾校一点通错题练习驾校一点通错题练习驾校一点通错题练习
联达驾校科目一模拟考试
欢迎使用本驾校综合管理系统. www.liublog.com.cn 有帮助文件 作者QQ:260052485 E-mail:liuyuelin007@126.com 若需C++源代码亦可联系作者。 软件登陆的初始账号和密码都为:1 软件涵盖了几乎驾校所有的管理模块; ...
驾校一点通软件
最新驾校一点通,具有模拟考试试题,保证驾驶考试,为以后成为专业驾驶员提供基础。
需要建立一个mysql数据库。因为软件问题无法导出,请读者自行创建。表的列数据在下载文件的截图中,因为程序有导出数据库到Excel文件和界面美化(共27个皮肤),所以需要导入两个jar包,在下载文件里,复制这两个...
2013_驾校一点通
数据结构驾校-驾校系统-驾校系统源码-驾校管理系统-驾校管理系统java代码-驾校系统设计与实现-基于springboot的驾校系统-基于Web的驾校系统设计与实现-驾校网站-驾校网站代码-驾校平台-驾校平台代码-驾校项目-驾校...
科学的管理方法让复杂的驾校信息管理工作尽可能的简化,汽车培训驾校管理软件将是您明智的选择。 本软件不仅支持单机使用,也支持多机联网使用,可以多部门、多人联网操作,数据共享。 管理包括: 学员管理、考试管理...
需要建立一个mysql表。因为软件问题无法导出,请读者自行创建。表的列数据在下载文件的截图中,因为程序有导出数据库到Excel文件和界面美化(共27个皮肤),所以需要导入两个jar包,在下载文件里,复制这两个文件在...
创新通汽车培训驾校管理软件(驾校培训管理)是一款绿色免费的专门为培训学员的驾校开发的业务综合管理软件。软件功能强大,适用于驾校培训管理行业。软件操作简单方便,界面美观大方,专门针对中小型驾校学员管理而...