Skip to content

Instantly share code, notes, and snippets.

@akamajoris
Created September 15, 2014 12:10
Show Gist options
  • Save akamajoris/5bf10471a013b4bdc8d5 to your computer and use it in GitHub Desktop.
Save akamajoris/5bf10471a013b4bdc8d5 to your computer and use it in GitHub Desktop.
ServerStatusParser
import urllib2, time, re
link = 'http://host/server-status'
data = []
period = 1 # sec
def get(link):
while True:
response = urllib2.urlopen(link)
html = response.read()
links = re.findall (r'<td nowrap>.*</td>', html)
for lnk in links:
lnk = lnk.replace("<td nowrap>","").replace("</td>GET ","").replace(" HTTP/1.0</td>","").replace("</td>HEAD ","").replace("</td>POST ","")
if lnk not in data:
with open("links.txt", "a") as f:
f.write(lnk + "\n")
data.append(lnk.replace("<td nowrap>","").replace("</td>GET ","").replace(" HTTP/1.0</td>","").replace("</td>HEAD ","").replace("</td>POST ",""))
time.sleep(period)
print "Total links:" + str(len(data))
get(link)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment