1 #-*-enconding:etf-8-*-2 ImportPymysql3 ImportOS4 Import Time5 ImportRe6Serveraddr="localhost"7User="Root"8password="123456"9Databasename="Test"TenFilename="./data/uncl.csv" One A defcreate_table (): - #Sep=os.sep - #tablename=raw_input (' Please input the table name which'll be created: ') the #classpath=raw_input (' Please enter a path to traverse: ') - -db=Pymysql.connect (serveraddr,user,password,databasename) -Cursor=db.cursor () +Cursor.execute ("drop table if exists ' Tncl '") -Sql="""CREATE TABLE ' Tncl ' ( + ' tncl_id ' varchar (+) NOT NULL, A ' tncl_tag ' varchar (+) NOT NULL, at ' tncl_desc ' varchar (255) is not NULL, - ' tncl_note ' varchar (+) is not NULL, - primary KEY (' tncl_id ') - ) engine=innodb default Charset=utf8;""" - - cursor.execute (SQL) in db.close () - defTest (): toP1=r"^\s{13}\w.+|\n$" +pattern=Re.compile (p1) -Fr=open (filename) theW2=open ('./data/e.csv','a') * forLineinchfr.readlines (): $ #print (line)Panax NotoginsengMatcher=Re.findall (pattern,line) - #print (Matcher) the #print (Type (matcher)) + forIinchMatcher: A W2.write (i) the #w2.write ("\ n") + fr.close () - w2.close () $ $ - if __name__=='__main__': -Test ()
Python Crawl Data Inbound MySQL