作者 herokay 发布的文章

疫情数据分析——Excel图表


Excel实现,套用公式,未用VBA,右侧地图用图片,如果要做成数据地图可参考https://www.sohu.com/a/307228212_817016
SVG地图获取不用那么麻烦,阿里云官网就有
http://datav.aliyun.com/tools/atlas
原教程第三步有点问题:

用excel导入emf的文件,然后ungroup这个地图变成freeform的图形,如下图。

这地方应改成:

用excel导入wmf的文件,然后取消组合这个地图变成freeform的图形,如下图。

所谓导入其实就是插入wmf图片,不是emf。
数据获取自己到官网查就行了,不管是百度还是腾讯,数据都只是到市,县区的数据还是得到官网查询。各地方卫健委的官网上可以查到数据。
宁夏卫健委:http://wsjkw.nx.gov.cn/yqfkdt/yqsd1.htm
宁夏的数据还可以从宁夏新闻网获取,这个有时候比官网更新的早。
http://www.nxnews.net/zt/2020/2020kjfy/2020nxyqb/
如果嫌麻烦又怕眼睛看花,可以用下面python脚本获取宁夏的详细数据,两个代码获取到的数据是一致的,只是实现方式有点区别。


代码一

import requests
import re
import time
from bs4 import BeautifulSoup

def UpdateUrl(date = time.strftime("%Y-%m-%d")):
    url = "http://www.nxnews.net/zt/2020/2020kjfy/2020nxyqb/"
    respons = requests.get(url)
    respons.encoding = 'utf-8'
    bs = BeautifulSoup(respons.text, "html.parser")
    # print(bs.title.get_text())
    item = bs.find(name='tr')
    isupdate = item.get_text().find(time.strftime("%Y-%m-%d"))
    if isupdate != -1:
        el = item.find(name='a')
        #text = el.get_text()
        href = re.sub(r'[^a-zA-Z0-9,\/:._]+', '', el.get('href'))
        #print(text)
        #print(href)
        return href
    else:
        #print("今日未更新!")
        return ''

def parData(url):
    data = {
        "银川市": 0,
        "兴庆区": 0,
        "西夏区": 0,
        "金凤区": 0,
        "永宁县": 0,
        "贺兰县": 0,
        "灵武市": 0,
        "石嘴山市": 0,
        "大武口区": 0,
        "惠农区": 0,
        "平罗县": 0,
        "吴忠市": 0,
        "利通区": 0,
        "红寺堡区": 0,
        "盐池县": 0,
        "同心县": 0,
        "青铜峡市": 0,
        "固原市": 0,
        "原州区": 0,
        "西吉县": 0,
        "隆德县": 0,
        "泾源县": 0,
        "彭阳县": 0,
        "中卫市": 0,
        "沙坡头区": 0,
        "中宁县": 0,
        "海原县": 0,
        "宁东": 0
    }
    respons = requests.get(url)
    respons.encoding = 'utf-8'
    bs = BeautifulSoup(respons.text, "html.parser")
    # print(bs.title.get_text())
    item = bs.find('div',class_='article')
    item = item.find_all('p')
    item = item[3]
    #print(item[3])
    #item.get_text()
    for k in data.keys():
        #data[k] = re.match(r'银川市[0-9]+例',item.get_text()).group()[len(key)-1:-1]
        reg_txt = k + '[0-9]+例'
        #print(reg_txt)
        res = re.search(reg_txt,item.get_text())
        if not res is None:
            #print(res)
            data[k] = res.group(0)[len(k):-1]
    return data

if __name__=="__main__":
    url=  UpdateUrl()
    if url != '':
        print(url)
        data = parData(url)
        for k in data.keys():
            print(k + "\t" + str(data[k]))
    else:
        print("今日尚未更新!")



代码二

import requests
import re
import time
from bs4 import BeautifulSoup

def UpdateUrl(date = time.strftime("%Y-%m-%d")):
    url = "http://www.nxnews.net/zt/2020/2020kjfy/2020nxyqb/"
    respons = requests.get(url)
    respons.encoding = 'utf-8'
    bs = BeautifulSoup(respons.text, "html.parser")
    # print(bs.title.get_text())
    item = bs.find(name='tr')
    isupdate = item.get_text().find(time.strftime("%Y-%m-%d"))
    if isupdate != -1:
        el = item.find(name='a')
        #text = el.get_text()
        href = re.sub(r'[^a-zA-Z0-9,\/:._]+', '', el.get('href'))
        #print(text)
        #print(href)
        return href
    else:
        #print("今日未更新!")
        return ''

def parData(url):
    data = {
        "银川市": 0,
        "兴庆区": 0,
        "西夏区": 0,
        "金凤区": 0,
        "永宁县": 0,
        "贺兰县": 0,
        "灵武市": 0,
        "石嘴山市": 0,
        "大武口区": 0,
        "惠农区": 0,
        "平罗县": 0,
        "吴忠市": 0,
        "利通区": 0,
        "红寺堡区": 0,
        "盐池县": 0,
        "同心县": 0,
        "青铜峡市": 0,
        "固原市": 0,
        "原州区": 0,
        "西吉县": 0,
        "隆德县": 0,
        "泾源县": 0,
        "彭阳县": 0,
        "中卫市": 0,
        "沙坡头区": 0,
        "中宁县": 0,
        "海原县": 0,
        "宁东": 0
    }
    respons = requests.get(url)
    respons.encoding = 'utf-8'
    bs = BeautifulSoup(respons.text, "html.parser")
    # print(bs.title.get_text())
    item = bs.find('div',class_='article')
    #item.get_text()
    qz_pos = re.search('累计报告',item.get_text())
    #print(qz_pos.start())
    for k in data.keys():
        #data[k] = re.match(r'银川市[0-9]+例',item.get_text()).group()[len(key)-1:-1]
        reg_txt = k + '[0-9]+例'
        #print(reg_txt)
        res = re.finditer(reg_txt,item.get_text())
        if res :
            for t in res:
                #print(t)
                if t.start() > qz_pos.start() : #小于新增
                    data[k] = t.group()[len(k):-1]
                    print(t.group())
                    break
                    #print(res)
    return data

if __name__=="__main__":
    url=  UpdateUrl()
    if url != '':
        print(url)
        data = parData(url)
        for k in data.keys():
            print(k + "\t" + str(data[k]))
    else:
        print("今日尚未更新!")


数据抓取.xlsx

宁夏“智慧疫控普查”自动填表

功能说明:宁夏“智慧疫控普查”自动填表,手动输入验证码后提交即可。

一、准备工作

1.软件:按键精灵


按键精灵下载及安装

下载地址:http://download.myanjian.com/

点击下载安装即可


按键精灵导入代码

方式一:新建后将代码直接粘贴到源代码里。

方式二(推荐):将下载解压好的xxx.q直接拖到按键精灵中,点几次下一步完成即可。

2.PC端微信,且默认浏览器必须是微信自动浏览器


PC端微信浏览器打开页面

用手机端微信浏览器扫码打开填报页面,然后分享到PC端微信,用微信浏览器打开页面即可。

二、代码

运行代码一必须确保本地Excel能正常打开运行,代码一运行速度比代码二稍慢。

代码一


代码一(依赖本地Excel)

'Hwnd = Plugin.Window.Find(CefWebViewWnd, 0)
'Call Plugin.Window.Active(Hwnd)
Call Plugin.Office.OpenXls("C:\temp\套湾.xlsx")

Dim index, name, sex, id, phone,hz,dw,target

index = 0
For i = 2 To 500
    name = Plugin.Office.ReadXls(1, i, 2)
    target = Plugin.Office.ReadXls(1, i, 8)
    If name <> "" and target = "" Then 
        index = i
        Goto abc
    End If
Next
Call Plugin.Office.CloseXls()

rem abc
name = Plugin.Office.ReadXls(1, index, 2)
sex = Plugin.Office.ReadXls(1, index, 3)
id = Plugin.Office.ReadXls(1, index, 4)
phone = Plugin.Office.ReadXls(1, index, 5)
hz = Plugin.Office.ReadXls(1, index, 6)
dw = Plugin.Office.ReadXls(1, index, 7)

Call Plugin.Office.WriteXls(1, index, 8, "是")
'两次Tab切换到市
KeyPress "Tab", 2
Delay 200
'4次 Down选中中卫市
KeyPress "Down", 4
Delay 500
'Tab切换到县区
KeyPress "Tab", 1
Delay 200
'3次Down选中海原县
KeyPress "Down", 3
Delay 500
'Tab切换到乡镇
KeyPress "Tab", 1
Delay 200
'3次Down选中西安镇
KeyPress "Down", 4
Delay 500
'Tab切换到村组
KeyPress "Tab", 1
Delay 200
'3次Down选中小河村
KeyPress "Down", 4
Delay 500
'输入村组
KeyPress "Tab", 1
Delay 200
SayString "套湾"
Delay 500
'Tab切换到楼号
KeyPress "Tab", 1
Delay 200
SayString hz & "家"
Delay 500
'Tab切换人员类别
KeyPress "Tab", 1
Delay 200
'8次Down选中H
KeyPress "Down", 8
Delay 200
'Tab切换到姓名
KeyPress "Tab", 1
Delay 200
SayString name
Delay 500
'Tab切换到性别  默认男,如果是女在Down一次
KeyPress "Tab", 1
Delay 200
If sex = "女" Then 
    KeyPress "Down", 1
    Delay 500
End If
'Tab切换到身份证号
KeyPress "Tab", 1
Delay 200
SayString id
Delay 500
'Tab切换到户籍地址
KeyPress "Tab", 1
Delay 200
SayString "海原县西安镇小河行政村套湾" & hz & "家"
Delay 500
'Tab切换到 本人本市内存在无人居住的空置房  默认否
KeyPress "Tab", 1
Delay 200
'Tab切换到 手机号
KeyPress "Tab", 1
Delay 200
SayString phone
Delay 200
'Tab切换到 工作单位
KeyPress "Tab", 1
Delay 200
SayString dw
Delay 200
'6次Tab切换到 目前健康状况,默认健康
KeyPress "Tab", 6
Delay 200
'Tab切换到 1月17日以来与A\B\C\D四类人员有密切接触:
KeyPress "Tab", 1
Delay 200
KeyPress "Down", 1
Delay 200
'Tab切换到 是否与确诊或疑似病例有密切接触
KeyPress "Tab", 1
Delay 200
KeyPress "Down", 1
Delay 200
'Tab切换到 是否隔离
KeyPress "Tab", 1
Delay 200
KeyPress "Down", 1
Delay 200
Call Plugin.Office.CloseXls()
Call Plugin.Msg.Tips("脚本运行结束")

代码二


代码二(不依赖其他软件,速度更快)

'读取上次位置信息
LogFL = Plugin.File.OpenFile("C:\temp\log.txt")
Call Plugin.File.SeekFile(LogFL,0)
ps = Plugin.File.ReadLine(LogFL)
If ps = "" Then 
    ps = 0
End If
Call Plugin.File.SeekFile(LogFL,0)
Call Plugin.File.WriteLine(LogFL,ps+1)
Call Plugin.File.CloseFile(LogFL)
'根据位置信息读取数据
FL = Plugin.File.OpenFile("C:\temp\套湾.csv")
text = Plugin.File.ReadLine(FL)
For i = 0 To ps
    text = Plugin.File.ReadLine(FL)
Next
Call Plugin.File.CloseFile(FL)
'填表单
sp = split(text, ",")
name = sp(1)
sex = sp(2)
id = sp(3)
phone = sp(4)
hz = sp(5)
dw = sp(6)
'两次Tab切换到市
KeyPress "Tab", 2
Delay 200
'4次 Down选中中卫市
KeyPress "Down", 4
Delay 500
'Tab切换到县区
KeyPress "Tab", 1
Delay 200
'3次Down选中海原县
KeyPress "Down", 3
Delay 500
'Tab切换到乡镇
KeyPress "Tab", 1
Delay 200
'3次Down选中西安镇
KeyPress "Down", 4
Delay 500
'Tab切换到村组
KeyPress "Tab", 1
Delay 200
'3次Down选中小河村
KeyPress "Down", 4
Delay 500
'输入村组
KeyPress "Tab", 1
Delay 200
SayString "套湾"
Delay 500
'Tab切换到楼号
KeyPress "Tab", 1
Delay 200
SayString hz
Delay 500
'Tab切换人员类别
KeyPress "Tab", 1
Delay 200
'8次Down选中H
KeyPress "Down", 8
Delay 200
'Tab切换到姓名
KeyPress "Tab", 1
Delay 200
SayString name
Delay 500
'Tab切换到性别  默认男,如果是女在Down一次
KeyPress "Tab", 1
Delay 200
If sex = "女" Then 
    KeyPress "Down", 1
    Delay 500
End If
'Tab切换到身份证号
KeyPress "Tab", 1
Delay 200
SayString id
Delay 500
'Tab切换到户籍地址
KeyPress "Tab", 1
Delay 200
SayString "海原县西安镇小河行政村" & hz & "家"
Delay 500
'Tab切换到 本人本市内存在无人居住的空置房  默认否
KeyPress "Tab", 1
Delay 200
'Tab切换到 手机号
KeyPress "Tab", 1
Delay 200
SayString phone
Delay 200
'Tab切换到 工作单位
KeyPress "Tab", 1
Delay 200
SayString dw
Delay 200
'6次Tab切换到 目前健康状况,默认健康
KeyPress "Tab", 6
Delay 200
'Tab切换到 1月17日以来与A\B\C\D四类人员有密切接触:
KeyPress "Tab", 1
Delay 200
KeyPress "Down", 1
Delay 200
'Tab切换到 是否与确诊或疑似病例有密切接触
KeyPress "Tab", 1
Delay 200
KeyPress "Down", 1
Delay 200
'Tab切换到 是否隔离
KeyPress "Tab", 1
Delay 200
KeyPress "Down", 1
Delay 200
Call Plugin.Office.CloseXls()
Call Plugin.Msg.Tips("脚本运行结束")

三、资源准备

1.制作Excel数据

每一列的位置不能变,H列是否上报,制作时空着即可。

提取性别公式=IF(MOD(MID(D2,17,1),2)=0,"女","男")提取后复制再粘贴为值

![](http://www.herokay.cn/usr/uploads/2020/02/1786846554.png)

2.Excel转csv格式(代码一不用这一步操作)

点击另存为,保存为csv格式即可,警告信息不用管确定即可

![](http://www.herokay.cn/usr/uploads/2020/02/1489017096.png)

3.修改代码

每个人所处的市、县、区不一定相同,根据需要修改相应代码。

如何确定Tab后面次数要改为多少?

鼠标点一下上一个输入框,然后按一下Tab键,然后按键盘上向下的箭头,次能出现你需要的值就改为几次

代码一和代码二基本一致,这地方以代码二为例修改

![](http://www.herokay.cn/usr/uploads/2020/02/3050141479.png)

如果你两个代码都导入了,工作是指能选中一个运行,按键精灵默认按F10运行代码。

[代码.zip](http://www.herokay.cn/usr/uploads/2020/02/2603048172.zip)

Tampermonkey挂机脚本常用代码片段

每隔十几分钟弹出一个对话框

情况一、alert弹窗

window.alert=function(msg){console.info(msg);};

情况二、模态对话框

//临汾市2019——2020年度中小学幼儿园教师全员培训项目 可用
//http://px.yanxiu.com/2019sx_6041/index.html
function myGJ()
{
    var display =$('.clock-tip').css('display'); 
    if(display != 'none')
    {
        $('.clock-tip').click();
    }
}

setInterval(myGJ, 5000);

失去焦点后停止计时

window.onblur=null;

10分钟不操作停止计时

//使用网站 http://tn201964013.stu.teacher.com.cn
setInterval('countss=0;', 8*60*1000);

通过MutationObserver监控代码修改触发相应代码

//选择一个需要观察的节点
var targetNode = document.getElementById('some-id');

// 设置observer的配置选项
var config = { attributes: true, childList: true, subtree: true };

// 当节点发生变化时的需要执行的函数
var callback = function(mutationsList, observer) {
    for(var mutation of mutationsList) {
        if (mutation.type == 'childList') {
            console.log('A child node has been added or removed.');
        }
        else if (mutation.type == 'attributes') {
            console.log('The ' + mutation.attributeName + ' attribute was modified.');
        }
    }
};

// 创建一个observer示例与回调函数相关联
var observer = new MutationObserver(callback);

//使用配置文件对目标节点进行观测
observer.observe(targetNode, config);

// 停止观测
observer.disconnect();

具体使用时可以简化

//选择一个需要观察的节点
var targetNode = document.getElementById('zwwx');

// 设置observer的配置选项
var config = { attributes: true };

// 当节点发生变化时的需要执行的函数
var callback = function(mutationsList, observer) {
    console.info(targetNode.style.display);
};

// 创建一个observer示例与回调函数相关联
var observer = new MutationObserver(callback);

//使用配置文件对目标节点进行观测
observer.observe(targetNode, config);

// 停止观测
observer.disconnect();