公司有100多台Dell的服务器,保修期参差不齐,什么日子都有。
麻烦来了,怎么查询一下服务器的保修期呢?
首先是批量发service tag号给dell官方问问,结果是给了一个网址,让自己查!!!
http://www.dell.com/support/home/cn/zh/cnbsd1?c=cn&l=zh&~ck=mn
这个网址适合单台查,没有批量的入口,更糟糕的是,必须输入验证码。
没办法,先去注册个dell的账号,然后登陆。
打开chrome,登陆dell账号后,按F12打开调试,然后打开下面的网址:
http://www.dell.com/support/home/cn/zh/cnbsd1/product-support/servicetag/FTQJY01/warranty
点到network,然后看左侧的下载资源
在wrapper.js下面,有个非常长的资源,点击之
点到右边的Header,往下拉就看到Header里面的Cookie了,拷贝下来。
首先编辑一个servicecode.txt文件,把所有机器的Service Tag号逐行粘贴进去。
然后编辑个python文件,注意把保存的Cookie内容替换到文件中'Cookie': 'XXXX'的XXXX部分。
然后运行即可,结果保存在result.txt中。
注意,这个程序比较脆弱,cookie过期,或者网络状况不好,都会出现read socket timout的现象。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2017-2-15
# @Author : 独自等待 (xliang@vip.qq.com)
# @Link : https://www.waitalone.cn/
# @Version : v2.0
try:
from lxml import html
except ImportError:
raise SystemExit("未找到lxml模块,请使用pip安装后运行!")
import urllib2
headers = {
'Upgrade-Insecure-Requests': '1',
'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
'Cookie': 'XXXX'
}
def ServiceCode(sc):
"Dell保修详情自动查询函数"
sc_url = 'http://www.dell.com/support/home/cn/zh/cnbsd1/product-support/servicetag/%s/warranty' % sc
towrite = u'您的 %s 的保修详情:\n' % sc
result_file = open('results.txt', 'ab+')
try:
req = urllib2.Request(sc_url, headers=headers)
res = urllib2.urlopen(req, timeout=30).read().decode('utf-8')
except Exception as e:
raise e
else:
ll = html.fromstring(res)
tags = ll.xpath('//span[@class="not-bold"]/text()')
stoptime = ll.xpath('//table[2]/tbody/tr/td[3]/text()')[0]
stag = tags[0]
sdeliver = tags[1]
print u'\n服务标签:%s 发货日期:%s 结束日期:%-10s\n' % (stag, sdeliver, stoptime)
towrite += u'\n服务标签:%s 发货日期:%s 结束日期:%-10s\n' % (stag, sdeliver, stoptime)
result_file.write(towrite.encode('utf-8') + '\n')
result_file.close()
def ReadCode(sfile):
"读取服务代码函数"
with open(sfile) as sfiles:
lines = sfiles.readlines()
for line in lines:
ServiceCode(line.strip())
if __name__ == '__main__':
scfile = 'servicecode.txt' # 指定servicecode文件名称
ReadCode(scfile)