zoukankan      html  css  js  c++  java
  • 团队项目-第二阶段冲刺-6

    一、说在前面

    1、今天任务:分词实现

    2、明天任务:定时任务

    3、遇到问题:无

    二、效果

     

      三、代码

    from jieba.analyse import *
    from lxml import etree
    from pymysql import connect
    import requests
    import jieba
    
        # 保存数据
    def getData():
        # 打开数据库连接(ip/数据库用户名/登录密码/数据库名)
        con = connect("localhost", "root", "root", "news")
        # 使用 cursor() 方法创建一个游标对象 cursor
        cursors = con.cursor()
        # 使用 execute()  方法执行 SQL 查询 返回的是你影响的行数
        row = cursors.execute("select * from newslist ")
        # 使用 fetchone() 方法获取数据.
        result = cursors.fetchall()
        keyWord = []
        for news in result:
            str = ''
            for keyword, weight in extract_tags(news[6].strip(), topK=5, withWeight=True):
                if(keyword.isdigit() != True):
                    str += keyword+" "
            keyWord.append(str)
        con.commit()
        # 关闭数据库连接(别忘了)
        print(keyWord)
        con.close()
        #
        #     guanjian += keyword+" "
    if __name__ == '__main__':
        getData()
  • 相关阅读:
    257. Binary Tree Paths
    324. Wiggle Sort II
    315. Count of Smaller Numbers After Self
    350. Intersection of Two Arrays II
    295. Find Median from Data Stream
    289. Game of Life
    287. Find the Duplicate Number
    279. Perfect Squares
    384. Shuffle an Array
    E
  • 原文地址:https://www.cnblogs.com/wyhqj/p/12907315.html
Copyright © 2011-2022 走看看