Created
September 15, 2014 12:10
-
-
Save akamajoris/5bf10471a013b4bdc8d5 to your computer and use it in GitHub Desktop.
ServerStatusParser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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