import glob
import os
import os.path
import sys
import urllib
from BeautifulSoup import BeautifulSoup
import pickle
import sgmllib
from pprint import pprint
import re
import MySQLdb

 def InsertMovieData():
        db = MySQLdb.connect(host="121.254.251.82", user="color", passwd="", db="DuplicatedDB", charset='utf8')
        cursor = db.cursor()

        #file_source = open('photo_unique_keys.htm','r')
        #fsoup = BeautifulSoup(file_source)
        for i in range( 2000, 62000, 1000 ):
                httpurl = 'http://192.168.33.192:3001/photo_unique_keys?index=' + str(i)
                html_source = urllib.urlopen(httpurl).read()
                soup = BeautifulSoup(html_source)

                for tag in soup.findAll('img', width="300"):
                        ntag = str(tag).replace('<img width="300" src="', '').replace('" />', '')
                        #query = "Update MovieData Set ImagePath='" + str(ntag) + "'"
                        query = "Insert Into MovieData(ImagePath) Values('" + str(ntag) + "')"
                        #print query
                        cursor.execute(query)
                        print ntag

        #file_source.closed

        db.close()

 def InsertNewsData(httpurl,group):
        db = MySQLdb.connect(host="121.254.251.82", user="color", passwd="", db="DuplicatedDB", charset='utf8')
        cursor = db.cursor()

        html_source = urllib.urlopen(httpurl).read()
        soup = BeautifulSoup(html_source)

        for tag in soup.findAll('img', width="200"):
                ntag = str(tag).replace('<img src="', '').replace('" width="200" />', '')
                #print ntag
                query = "Insert Into NewsData(ImagePath, newsgroup) Values('" + str(ntag) + "', " + str(group) + ")"
                #print query
                cursor.execute(query)

        db.close()


if __name__ == '__main__':
        #InsertMovieData()
        InsertNewsData(sys.argv[1], sys.argv[2])

'Programming > Python' 카테고리의 다른 글

Network programming with the Twisted framework, Part 1  (0) 2010.03.05
Posted by 한효정

블로그 이미지
착하게 살자.
한효정

카테고리

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.3
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

최근에 올라온 글

최근에 달린 댓글

글 보관함