So during a little bit of free time I wrote this
I have commented on the code, it's a very simple time scraper!
# Time grabber by LKP # Python Version 2.7 # Requires LXML from lxml import html import requests import os print "Which country would you like to know the time of?" # Asks the user which country they would like to know the time of. country = raw_input("> ") # Country variable replacement = country.replace(" ","_") # If you enter in a country like "United Kingdom" the website TheTimeNow.com requires an underscore in its URL i.e. http://www.thetimenow.com/United_Kingdom so this replaces a "space" in the two words meaning it doesn't error. page = requests.get("http://www.thetimenow.com/"+replacement) # Gets the entire page tree = html.fromstring(page.text) # Converts it into a simple tree for LXML to read time = tree.xpath('//span[@id="main_time"]/text()') # Reads the Span tag with the ID "main_time" print "The current time in",country,"is",time[0] # Prints the users selected country along with the current time including PM/AM
Hope you enjoy it!