Skip to content

Instantly share code, notes, and snippets.

@edwindotcom
Last active October 30, 2019 23:22
Show Gist options
  • Save edwindotcom/d1e3c6b8731311e3c8559cb818723f93 to your computer and use it in GitHub Desktop.
Save edwindotcom/d1e3c6b8731311e3c8559cb818723f93 to your computer and use it in GitHub Desktop.
# usage - run:
# python getTitle.py URL
from urllib2 import urlopen
import sched, time
from time import gmtime, strftime
import lxml.html
import sys
url = sys.argv[1]
print url
s = sched.scheduler(time.time, time.sleep)
count = 0
def check_title(arg):
global count
tree = lxml.html.parse(urlopen(url+"?"+str(count)))
pi = tree.xpath("//title")[0]
now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
print (now + " : " + pi.text)
count += 1
s.enter(2, 1, check_title, (arg,))
s.enter(2, 1, check_title, (s,))
s.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment