爬虫数据库
import sqlite3
contect = sqlite3. connect( './testsqlite.db' )
cursor = contect. cursor( )
cursor. execute( """
create table if not exists student (
id integer primary key,
name Text,
age integer
);
""" )
cursor. execute( ( """
insert into student (name,age) values ('小明',13);
""" ) )
import jieba
import sqlite3
connect = sqlite3. connect( './testsqlite.db' )
cursor = connect. cursor( )
cursor. execute( """select * from jdcom;""" )
comments_rs = cursor. fetchall( )
comments = [ c[ 2 ] for c in comments_rs]
comments = '' . join( comments)
words = jieba. cut( comments, cut_all= False )
print ( '/' . join( words) )
comment_word_list = [ '苹果' , '手机' , '外形外观' , '不错' , '还' , '苹果' , '8' , ',' , '。' ]
with open ( './dict/stop_words_zh.txt' , mode = 'r' , encoding= 'utf-8' ) as f:
stop_words = f. readlines( )
stop_words = [ stop_word. strip( ) for stop_word in stop_words]
print ( stop_words)
filered_comment_word_list = [ ]
for word in comment_word_list:
if word not in stop_words:
filered_comment_word_list. append( word)
print ( filered_comment_word_list)