python实训day05

爬虫数据库

  • sqlite数据库
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);
"""))
  • jieba分词
import jieba
import sqlite3
connect = sqlite3.connect('./testsqlite.db')
cursor = connect.cursor()
cursor.execute("""select * from jdcom;""")
comments_rs = cursor.fetchall()
# [(id, cid, content, product. color), (]
# comments = []
#处理列表里的每一一项,生成新列老,这个结构非常宿用。
# for c in comments_rs:
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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值