Mercurial > ~darius > hgwebdir.cgi > scrape-gm
comparison scrape-gm.py @ 6:5058c2695109
Properly report if we can't parse the results.
author | darius |
---|---|
date | Sun, 18 Nov 2007 08:54:07 +0000 |
parents | 294581b9c72f |
children | 825302e32c35 789cf10ce4c9 |
comparison
equal
deleted
inserted
replaced
5:294581b9c72f | 6:5058c2695109 |
---|---|
3 ############################################################################ | 3 ############################################################################ |
4 # Screen scraper for game-monitor.com | 4 # Screen scraper for game-monitor.com |
5 # | 5 # |
6 # Prints out matched player names agreated by server | 6 # Prints out matched player names agreated by server |
7 # | 7 # |
8 # $Id: scrape-gm.py,v 1.2 2007/10/19 07:53:00 darius Exp $ | 8 # $Id: scrape-gm.py,v 1.3 2007/11/18 08:54:07 darius Exp $ |
9 ############################################################################ | 9 ############################################################################ |
10 # | 10 # |
11 # Copyright (C) 2007 Daniel O'Connor. All rights reserved. | 11 # Copyright (C) 2007 Daniel O'Connor. All rights reserved. |
12 # | 12 # |
13 # Redistribution and use in source and binary forms, with or without | 13 # Redistribution and use in source and binary forms, with or without |
98 def Scrape(handle): | 98 def Scrape(handle): |
99 s = BeautifulSoup.BeautifulSoup(handle) | 99 s = BeautifulSoup.BeautifulSoup(handle) |
100 | 100 |
101 playertbl = s.find("table", "search_table") | 101 playertbl = s.find("table", "search_table") |
102 if (playertbl == None): | 102 if (playertbl == None): |
103 print "Unable to find results" | 103 #print "Unable to find results" |
104 return None | 104 return None |
105 | 105 |
106 servertbl = playertbl.findNext("table", "search_table") | 106 servertbl = playertbl.findNext("table", "search_table") |
107 | 107 |
108 playerrows = playertbl.findAll("tr") | 108 playerrows = playertbl.findAll("tr") |
151 print "Unable to fetch page - " + str(e) | 151 print "Unable to fetch page - " + str(e) |
152 sys.exit(0) | 152 sys.exit(0) |
153 | 153 |
154 servers = Server.Scrape(f) | 154 servers = Server.Scrape(f) |
155 del f | 155 del f |
156 if (len(servers) == 0): | 156 if (servers == None): |
157 print "No results available, please check manually" | |
158 elif (len(servers) == 0): | |
157 print "No players found" | 159 print "No players found" |
158 else: | 160 else: |
159 i = 0 | 161 i = 0 |
160 for s in servers: | 162 for s in servers: |
161 i = i + 1 | 163 i = i + 1 |