Dell保修批量查询脚本,帮同事写的,有需要的拿去用吧。
详情介绍:
1、从dell 的官方网站查询,确保准确。
2、不登录时需要验证码,登录后则不需要,所以需要保存登录后的cookie到cookie.txt中。
3、将要查询的保修代码保存到servicecode.txt中,一行一个。
4、脚本容错不多,如果出现错误,可能是cookie过期,导致了查询失败。
5、使用lxml解析html,速度还可以,只是dell网站速度比较慢。
6、如果只需要开始日期和结束日期,请使用v2版本,v1版本更详细。
Cookie信息获取方法:
登录状态下,访问下面的查询URL,然后按F12,查看请求头里面的cookie信息,全部复制,然后保存到cookie.txt中。
Dell查询URL为:
http://www.dell.com/support/home/cn/zh/cnbsd1/product-support/servicetag/FTQJY01/warranty
脚本代码如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-2-15 # @Author : 独自等待 ([email protected]) # @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': open('cookie.txt').read() } 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)
脚本打包下载:
from www.waitalone.cn.thanks for it.
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论