As I mentioned in my blog on my first learning resources, right after finishing the Google training, the first script I wrote was a script to get a Dell hardware warranty expiration given the service tag. It was my first attempt at web scraping, something you learn with the Google python videos. I am not sure if this is the best or most efficient way to do this, but it was a way for me to test out what I just learned. If you have some advice, don’t hesitate to share it in the comments.

I’m actually going to do more with this as I learn more. The goal is to access our database of hardware, grab the service tags, get the warranty expiration from Dell, and lastly update a warranty field in the database. From that field, we’ll generate alerts to notify customers of their pending expiration date and hopefully get some warranty sales. This script will be a part of that bigger picture later.

For now, all you do is run SERVICETAG to get the date back in a string format.

This script grabs the html and then searches for TopTwoWarrantyListItem. From that starting point, it looks for four greater than brackets to find the beginning position of the date. Then it looks for the very next less than bracket as the ending point for the date.

When I started typing up this blog, I ran the script and it was giving me errors. It worked when I wrote it, but I’ve since rebuilt my laptop with Linux Mint. My laptop was previously running CentOS, which I believe runs Python 2.6 as default. I’m assuming something changed from there. Considering the current training I’m doing is in Python 3, I made the script check for the python version and error out if not version 3.

Without further ado, here’s the Dell warranty script code.



profilepicJason Vanzin is the CEO at Vanzin Consulting Corp. He has over 15 years of IT experience and lives in Pittsburgh, PA. He blogs on topics related to Business Continuity, Python programming, and technology in general.

1 Comment

  1. Ronald Reynolds says:

    This is great, it gives me all sorts of ideas I never considered before!

    Here is a slightly tweaked version for Python 2.7

    import sys #module used to receive command line arguments into script and check python version
    # if sys.version.startswith(‘2.’):
    # print(“Script only runs in Python 3 and above.”)
    # sys.exit(1)
    import urllib2 #module used to request Dell webpage

    def getwarranty(servicetag):

    “”” (str) -> str
    Returns date as string by downloading html as a string and performing a regex search
    to find the date.

    u = “” + servicetag + \
    f = urllib2.urlopen(u)
    contents = str(
    i = 0
    warranty = “”
    while True:
    i = contents.find(‘TopTwoWarrantyListItem’, i)
    if i == -1:
    i = contents.find(‘>’, i + 1)
    i = contents.find(‘>’, i + 1)
    i = contents.find(‘>’, i + 1)
    i = contents.find(‘>’, i + 1)
    j = contents.find(‘<', i + 1)
    warranty = contents[i+1:j]

    return warranty

    def main():
    args = sys.argv[-1] # Get last word from commandline so it can be checked to see if it's a service tag.
    if not args:
    print('usage: [servicetag]')
    if '' in args:
    print('usage: [servicetag]')
    servicetag = sys.argv[-1]
    warrantyexpiration = getwarranty(servicetag)
    if warrantyexpiration == "":
    print("Service tag", servicetag, "not found.")

    if __name__ == '__main__':

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: