Created
January 6, 2010 04:02
-
-
Save saillinux/269999 to your computer and use it in GitHub Desktop.
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 httplib2, re | |
import MySQLdb | |
from BeautifulSoup import BeautifulSoup | |
entries = [] | |
h = httplib2.Http('.cache') | |
URL = 'http://www.worldofwarcraft.co.kr/news/notice/index.do?currpage=%s' | |
for seq in range(1, 4): | |
try: | |
response, content = h.request(URL % seq) | |
except: | |
print "An unhandled exception occured, here's the trackback" | |
traceback.print_exc() | |
if response['status'] == '200': | |
soup = BeautifulSoup(content) | |
table = soup.findAll(attrs = {'id' : 'Table'})[0] | |
for tr in table.findAll('tr', height=27): | |
items = tr.findAll('td') | |
if items[0].string != None: | |
tmp = items[2].string.split('.') | |
date = "-".join(["2%03d" % int(tmp[0]), tmp[1], tmp[2]]) | |
entries.append((dict(items[1].a.attrs)['title'], date, items[3].string)) | |
else: | |
print "die bitch" | |
exit(0) | |
db = MySQLdb.connect(db='announce', user='jeen',passwd='babo', | |
host='localhost', use_unicode=True, charset='utf8') | |
cursor = db.cursor() | |
for (title, date, lookup) in entries: | |
query = "INSERT INTO entry(title, date, lookup) VALUES ('%s', '%s', '%s')" | |
% (title, date, lookup) | |
cursor.execute(query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment