Beispiel #1
0
def getText():
    txt = open(r"C:\Users\CYG\Desktop\keyword_text.txt", "r",
               encoding='utf-8').read()
    # print(txt)
    txt = txt.lower()
    pattern = re.compile(
        r'\t|\n|\.|-|:|;|\)|\(|\?|\s[0-9]{1,2}\s|"')  # 定义正则表达式匹配模式(空格等)
    txt = re.sub(pattern, ' ', txt)
    # print(string_data)
    text = txt.split()
    res = collections.Counter(text)
    word_counts_top = res.most_common(1500)
    # print(word_counts_top)
    mysql = Mysql(dbname='736')
    for sort_name, num in word_counts_top:
        if len(sort_name) >= 3:
            try:
                print(sort_name, num)
                insert_data = []
                # pattern = re.compile("[^a-zA-Z0-9]")
                # sort_name = pattern.sub('',sort_name)
                filter_list = [
                    'con', 'product', 'products', 'solutions', 'solution',
                    'blog', 'css', 'js', 'images', 'infoimages', 'fonts',
                    'static', 'ajax'
                ]
                if sort_name not in filter_list and len(
                        sort_name) >= 3:  #注意一些特殊语言的掺杂其中 所以加了个长度判定
                    insert_data.append({'sort_name': sort_name})
                    insert_data.append({'num': num})
                    mysql.table('sort_name').insert(insert_data)
            except BaseException as e:
                print(e)
def main():
    # 创建页码队列
    redisqueue = RedisQueue('keyword_url')
    qsize = redisqueue.qsize()
    mysql = Mysql()
    for i in crawl_thread_list:
        download_thread = CrawlThread(i, redisqueue, qsize, time.time(), mysql)
        download_thread.start()
    print(qsize)
    time.sleep(20)
    print('采集结束')
    pass
Beispiel #3
0
def getTextMysql():
    txt = open(r"D:\pydata\work\scrapy_data\www.ogniskanadziei.pl.txt",
               "r",
               encoding='utf-8').read()
    # print(txt)
    txt = txt.lower()
    pattern = re.compile(
        r'\t|\n|\.|-|:|;|\)|\(|\?|\s[0-9]{1,2}\s|"')  # 定义正则表达式匹配模式(空格等)
    txt = re.sub(pattern, ' ', txt)
    # print(string_data)
    text = txt.split()
    text_all = collections.Counter(text)
    # print(text_all)
    word_counts_top = text_all.most_common()
    # print(word_counts_top)
    mysql = Mysql(dbname='scrapy')
    for sort_name, num in word_counts_top:
        if len(sort_name) >= 0:
            try:
                # print(sort_name,num)
                insert_data = []
                # pattern = re.compile("[^a-zA-Z0-9]")
                # sort_name = pattern.sub('',sort_name)

                res = mysql.table('sort_name').where([{
                    'sort_name': ['=', sort_name]
                }]).find()

                if res:
                    insert_data.append({'num': int(res[2]) + int(num)})
                    mysql.table('sort_name').where([{
                        'sort_name': ['=', sort_name]
                    }]).update(insert_data)
                else:
                    insert_data.append({'sort_name': sort_name})
                    insert_data.append({'num': num})
                    mysql.table('sort_name').insert(insert_data)
            except BaseException as e:

                print(e)
Beispiel #4
0
#物料词和非物料词扇形图

    def bar3(self):
        #(数量+id+物料名字)
        temp_x = []
        y = []
        num_tupple = self.get_material_bie()
        for i in num_tupple:
            temp_x.append(i[2])
            y.append(i[0])
        x = tuple(temp_x)
        print(x, y)
        plt.rcParams['font.sans-serif'] = ['SimHei']
        plt.rcParams['axes.unicode_minus'] = False
        x = range(len(temp_x))
        p1 = plt.bar(x, y)
        plt.xticks(x, temp_x)
        plt.show()
        pass
if __name__ == '__main__':
    mysql = Mysql(dbname='industro')
    data = Data(mysql)
    # data.bar3()
    # data.pie_show()
    if data.bie_or_bar == 1:
        data.pie_show()
    elif data.bie_or_bar == 2:
        data.pie_show2()
    else:
        data.bar_show()
    print('结束执行')
from mysql_class import Mysql

mysql = Mysql('localhost', 'root', 'password', 'ex01')

# param=str(input("情输入一个名字:"))

sql = 'insert into students(name) values(%s);'

# sql='update students set name=%s where id=1'

# sql1='delete from students where id=1'
# mysql.excute_one(sql,param)
# mysql.excute_one(sql1)

# sql='select name from students where id<6'
# result=mysql.get_one(sql)
result = mysql.excute_many(sql, ['xiaohua', 'xiama'])
print(result)
# 将数据传入哈希对象中, hashlib.sha1(password.encode('utf-8'))等价于m=hashlib.sha1()和
#  m.update(password.encode('utf-8'))这两句;当内容太长的时候,可以使用update多次更新内容,等效更新一次长数据
# m.update(password.encode('utf-8'))

# 获取二进制
# new_password = m.digest()

# 获取16进制
new_password1 = m.hexdigest()

# print(new_password)
# print(new_password1)

# 连接数据库
mydb = Mysql('localhost', 'root', 'password', 'ex01')

# 查询用户名和密码
sql = 'select password from userinfo where name=%s'

result = mydb.get_many(sql, (name))
print(result)

if len(result) == 0:
    print("用户名错误")
else:
    if result[0][0] == new_password1:
        print("登陆成功")
    else:
        print("密码错误")
Beispiel #7
0
from mysql_class import Mysql

import hashlib

# 用户输入
user = input("请输入名字:")
password = input("请输入密码:")

m = hashlib.sha1()
m.update(password.encode('utf-8'))
new_password = m.hexdigest()

param=[user,new_password]

mydb = Mysql('localhost', 'root', 'password', 'ex01')
sql = 'select name from userinfo'
names = mydb.get_many(sql)
# print(names)
for name in names:
    if name[0] == user:
        print(type(name[0]))
        print(user)
        print("该用户已经存在")
        break
else:
    sql1 = 'insert into userinfo(name,password) values(%s,%s)'
    mydb.excute_one(sql1, param)
    print("注册成功")
while True:
    # 用户输入
    name = input("请输入用户名:")
    password = input("请输入密码:")

    m = hashlib.sha1(password.encode('utf-8'))

    # 将数据传入哈希对象中, hashlib.sha1(password.encode('utf-8'))等价于m=hashlib.sha1()和
    #  m.update(password.encode('utf-8'))这两句;当内容太长的时候,可以使用update多次更新内容,等效更新一次长数据
    # m.update(password.encode('utf-8'))

    # 获取二进制
    # new_password = m.digest()

    # 获取16进制
    new_password1 = m.hexdigest()

    # print(new_password)
    # print(new_password1)

    # 连接数据库
    mydb = Mysql('localhost', 'root', 'password', 'ex01')

    # 插入数据,插入sha1的密码,方式一:格式化的方式输入
    # sql = 'insert into students(name,password) values("%s","%s")' % (name, new_password1)

    # 方式二:利用excute_one()中的param输入
    sql = 'insert into students(name,password) values(%s,%s)'
    print(sql)
    mydb.excute_one(sql,(name,new_password1))