从网页上抓取Windows补丁信息然后整型输出(Python)
Powershell实现:http://www.cnblogs.com/IvanChen/p/4488246.html
今天通过Python实现:
# coding=utf-8
import re
import requests
import csv
import sys
from lxml import etree reload(sys)
sys.setdefaultencoding('utf8') summaryurl = 'https://technet.microsoft.com/en-us/library/security/mt637763.aspx'
summarycontent = requests.get(summaryurl).content
selector = etree.HTML(summarycontent)
mslist = selector.xpath('//*[@id="mainBody"]/table/tr/td[2]/p/a/text()') pattern_published_date = re.compile(r"[a-zA-Z]*?\s[0-9]*?,\s[0-9]*")
pattern_severity = re.compile(r"[a-zA-Z]*$")
pattern_kbnumber = re.compile(r"\d+")
pattern_vultype = re.compile(r"Information Disclosure|Remote Code Execution|Elevation of Privilege|Security Feature Bypass|Cumulative Security Update|Denial of Service|Tampering|Spoofing", re.I) csvfile = file('eggs.csv', 'wb')
writer = csv.writer(csvfile, dialect="excel")
writer.writerow(['Date', 'MSRC', 'KB', 'Severity', 'Version', 'Summary', 'Type']) for eachmsrc in mslist:
msrcurl = "https://technet.microsoft.com/en-us/library/security/" + eachmsrc + ".aspx"
msrc_content = requests.get(msrcurl).content
msrc_selector = etree.HTML(msrc_content) published_date = msrc_selector.xpath('//*[@id="pubInfo"]/p[1]/text()')
kbnumber = msrc_selector.xpath('//*[@id="mainBody"]/h2/text()')
severity = msrc_selector.xpath('//*[@id="content"]/div[2]/h1/text()')
version = msrc_selector.xpath('//*[@id="pubInfo"]/p[2]/text()')
summary = msrc_selector.xpath('//*[@id="mainBody"]/div[3]/div/p[1]/text()')
vultype = msrc_selector.xpath('string(//*[@id="mainBody"]/div[3]/div)')
ft_published_date = re.search(pattern_published_date, published_date[0]).group()
ft_kbnumber = re.search(pattern_kbnumber, kbnumber[0]).group()
ft_severity = re.search(pattern_severity, severity[0].strip('\n ')).group()
ft_version = version[1]
ft_summary = summary[0]
ft_vultype = re.search(pattern_vultype, vultype)
if ft_vultype:
writer.writerow([ft_published_date, eachmsrc, ft_kbnumber, ft_severity, ft_version, ft_summary, ft_vultype.group()])
else:
vultype = msrc_selector.xpath('string(//*[@id="mainBody"]/div[position()>3]/div/table)')
ft_vultype = re.search(pattern_vultype, vultype)
writer.writerow([ft_published_date, eachmsrc, ft_kbnumber, ft_severity, ft_version, ft_summary, ft_vultype.group()])
csvfile.close()
从网页上抓取Windows补丁信息然后整型输出(Python)的更多相关文章
- 从网页上抓取Windows补丁信息然后整型输出(PowerShell)
$report = [pscustomobject]@{'Date' = $null; 'MSRC' = $null; 'KB' = $null; 'Severity' = $null; 'Versi ...
- python爬虫抓取哈尔滨天气信息(静态爬虫)
python 爬虫 爬取哈尔滨天气信息 - http://www.weather.com.cn/weather/101050101.shtml 环境: windows7 python3.4(pip i ...
- Android登录client,验证码的获取,网页数据抓取与解析,HttpWatch基本使用
大家好,我是M1ko.在互联网时代的今天,假设一个App不接入互联网.那么这个App一定不会有长时间的生命周期,因此Android网络编程是每个Android开发人员必备的技能.博主是在校大学生,自学 ...
- Java广度优先爬虫示例(抓取复旦新闻信息)
一.使用的技术 这个爬虫是近半个月前学习爬虫技术的一个小例子,比较简单,怕时间久了会忘,这里简单总结一下.主要用到的外部Jar包有HttpClient4.3.4,HtmlParser2.1,使用的开发 ...
- 爬虫---selenium动态网页数据抓取
动态网页数据抓取 什么是AJAX: AJAX(Asynchronouse JavaScript And XML)异步JavaScript和XML.过在后台与服务器进行少量数据交换,Ajax 可以使网页 ...
- Python爬虫实战---抓取图书馆借阅信息
Python爬虫实战---抓取图书馆借阅信息 原创作品,引用请表明出处:Python爬虫实战---抓取图书馆借阅信息 前段时间在图书馆借了很多书,借得多了就容易忘记每本书的应还日期,老是担心自己会违约 ...
- 教您使用java爬虫gecco抓取JD全部商品信息
gecco爬虫 如果对gecco还没有了解可以参看一下gecco的github首页.gecco爬虫十分的简单易用,JD全部商品信息的抓取9个类就能搞定. JD网站的分析 要抓取JD网站的全部商品信息, ...
- python写的爬虫工具,抓取行政村的信息并写入到hbase里
python的版本是2.7.10,使用了两个第三方模块bs4和happybase,可以通过pip直接安装. 1.logger利用python自带的logging模块配置了一个简单的日志输出 2.get ...
- FakeLogonScreen抓取Windows凭证
FakeLogonScreen抓取Windows凭证 实践中使用的配置 攻击者: 操作系统: Kali Linux 2020.1 IP: 192.168.1.13 目标: 作业系统: Windows ...
随机推荐
- 第3月第13天 cpp模版 Iterator模式 proactor
1.模版除了传参,还可以自动创建.而传指针只是传参而已. template <class TYPE, class FUNCTOR, class ACE_LOCK, typename TIME_P ...
- webview滑动事件 与内部html左右滑动事件冲突问题的解决办法
最近在做个混合app , 用html做页面,然后通过webview嵌套在activity中,效果是这样: 开始还是比较顺利,增加了菜单退出按钮,返回键页面回退功能,页面加载显示加载图标(在app端实现 ...
- Android中的动画机制
1 逐帧动画 逐帧动画 就是一系列的图片按照一定的顺序展示的过程. 逐帧动画很简单, 只需要在drawable中或者anim中定义一个Animation-list 其中包含多个it ...
- nginx负载均衡基于ip_hash的session粘帖
nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...
- SQL表新增触发(触发器)
ALTER TRIGGER [InsertStoreJITOnloadQuantity] ON [dbo].[Sourceing] After INSERT AS --登記計劃數量(新增時YN=0) ...
- 使用 CoordinatorLayout 实现复杂联动效果
GitHub 地址已更新: unixzii / android-FancyBehaviorDemo CoordinatorLayout 是 Google 在 Design Support 包中提供的一 ...
- 51nod1073(约瑟夫环)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1073 题意: 中文题诶~ 思路: 直接模拟的话O(n*k)的 ...
- 最小化安装centos7不能执行ifconfig命令的解决方法
操作环境 虚拟机:VirtualBox 5.0.4 for Windows 操作系统:CentOS-7-x86_64-Minimal-1503-01.iso 问题描述 登录系统之后,输入ifconfi ...
- [leetcode] 12. Integer to Roman
关于罗马数字: I: 1V: 5X: 10L: 50C: 100D: 500M: 1000字母可以重复,但不超过三次,当需要超过三次时,用与下一位的组合表示:I: 1, II: 2, III: 3, ...
- /var/run/yum.pid 已被锁定,PID 为 XXXX 的另一个程序正在运行。
安装st-load时, 终端提示 “/var/run/yum.pid 已被锁定,PID 为 13908 的另一个程序正在运行.” 解决方法:直接在终端运行 rm -f /var/run/yum.pid ...