Python
Crawler Class Sample
ElvinKim
2014. 9. 25. 10:46
데이터 Crawling 시에 python 코드 샘플
# # import modules # import MySQLdb import urllib import re # #URL # MAIN_URL = "http://www.test.com" # #TMPL # TMPL = "" # # CLASS crawler # class Crawler(object): def __init__(self): self.db = MySQLdb.connect(host="",user="",passwd="",db="") self.cur = self.db.cursor() def __del__(self): self.db.close() def run(self): html = urllib.urlopen(MAIN_URL) page = html.read() match = re.compile(TMPL , re.DOTALL) match_list = match.findall(page) if __name__ == "__main__": crawler = Crawler() crawler.run()