Environment: python2.7
Comsenzxp comes with MySQL
Installing the Python-mysql module
Data format: Account information in TXT format.
Data is one line of data.
Difficulties: Some lines only account, no password, some are empty lines, some lines at the end of the line have three quotation marks, some empty lines, some are not account password information.
Code implementation:
1 #!/usr/bin/env python2 #Encoding:utf-83 4 5 """6 @version:??7 @author: Elijahxb8 @contact: elijahxb@163.com9 @site:Ten @software: pycharm Community Edition One @file: main.py A @time: 2017/7/8 23:47 - """ - ImportMySQLdb the ImportOS -#ImportRe - -CONN_IP ='127.0.0.1' +Conn_username ='Root' -Conn_password ='11111111' +Conn_database ='Qqdata' AConn_table ='Login' atConn_port = 3306 - -Importpath = u"""D:\QQ Database""". Encode ("GBK") -Pattern ="[0-9,a-z,a-z]{4,12}" -Sumlist = [] - defGett (path): inFiledata = [] -Onedata = [] toFileList =os.listdir (path) + forFileinchfilelist: - Print "Processing Files ..."+file theWith open (Os.path.join (path,file),'R') as FH: *Lines =Fh.readlines () $ forIndex,lineinchEnumerate (lines):Panax Notoginseng Print "processing {0} row data, progress {0}/{1}, ' {2} '". Format (Index,len (lines), Str (FLOAT ("%0.2f"% (float (index)/len (lines))) *100) +"%") - ifLen (line) < 14: the Continue + elif '"""' inchLine : Aline = Line.split ('"""') [1] thetext_l = Line.split (" ") +Username =Text_l[0] -passwd = Text_l[1].split ("\ n") [0] $ ifLen (username) < 4orLen (passwd) < 4: $ Continue - onedata.append (username) -Onedata.append ("'"+ passwd +"'") the filedata.append (Tuple (onedata)) -Onedata = []WuyiFiledata = List (set (Filedata))#clears all duplicates in a file the sumlist.append (Tuple (filedata)) - returnsumlist Wu - About $conn = MySQLdb.connect (host =Conn_ip, -user =Conn_username, -passwd =Conn_password, -db =Conn_database, APort =Conn_port + ) theCur =conn.cursor () -Cur.execute ("Use qqdata") $Cur.execute ("TRUNCATE TABLE Login") thesqlcmd ="INSERT INTO login (QQ,PWD) VALUES (%s,%s)" thet =Gett (Importpath) the forSinglefiledatainchT: the Cur.executemany (sqlcmd,singlefiledata) - cur.close () inConn.close ()