diff --git a/pythonProject/.idea/.gitignore b/pythonProject/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/pythonProject/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/pythonProject/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/pythonProject/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/pythonProject/.idea/misc.xml b/pythonProject/.idea/misc.xml new file mode 100644 index 0000000..2a01189 --- /dev/null +++ b/pythonProject/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/modules.xml b/pythonProject/.idea/modules.xml new file mode 100644 index 0000000..e15ec35 --- /dev/null +++ b/pythonProject/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/pythonProject.iml b/pythonProject/.idea/pythonProject.iml new file mode 100644 index 0000000..41b8950 --- /dev/null +++ b/pythonProject/.idea/pythonProject.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pythonProject/cf..py b/pythonProject/cf..py new file mode 100644 index 0000000..0cff032 --- /dev/null +++ b/pythonProject/cf..py @@ -0,0 +1,25 @@ +import requests + +url = 'https://codeforces.com/search?by=' + +name = input() + +params = { + 'query' : name +} + +headers = { + 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0' +} + +response = requests.get(url=url, params=params, headers=headers) + +page_text = response.text + +File = name + '.html' + +with open(File, 'w', encoding='utf-8') as fp: + fp.write(page_text) + + + diff --git a/pythonProject/db_log.txt b/pythonProject/db_log.txt new file mode 100644 index 0000000..e69de29 diff --git a/pythonProject/dp.py b/pythonProject/dp.py new file mode 100644 index 0000000..1cce2ac --- /dev/null +++ b/pythonProject/dp.py @@ -0,0 +1,63 @@ +import pymysql +import logging + +# 创见日志对象 +logger = logging.getLogger("db_log.txt") + +#输出格式 +formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + +#将文件输出的磁盘 +file_handler = logging.FileHandler('db_log.txt') + +#设置为设定好的输出个数 +file_handler.setFormatter(formatter) + +#设置文件等级 +logger.setLevel(logging.INFO) + +#添加进logger +logger.addHandler(file_handler) + +class DBHelper: + def __init__(self, host='localhost', port=3306, user='root', password='123456', db='qwq'): + self.host = host + self.user = user + self.password = password + self.db = db + self.port = port + self.conn = None + self.cur = None + + def connect(self): + try: + self.conn = pymysql.connect(host=self.host, port=self.port, user=self.user, password=self.password, db=self.db) + except: + logger.error('connect Error') + return False + self.cur = self.conn.cursor() + return True + + def execute(self, sql, params=None): + if not self.connect(): + return False + try: + if self.conn and self.cur: + self.cur.execute(sql, params) + self.conn.commit() + except: + logger.error(str(sql)) + return False + return True + + def close(self): + self.cur.close() + self.conn.close() + +if __name__ == '__main__': + db = DBHelper() + sql = 'create table films(title varchar(50), actor varchar(200), time varchar(100));' + db.execute(sql) + + db.close() + logger.removeHandler(file_handler) \ No newline at end of file diff --git a/pythonProject/login.py b/pythonProject/login.py new file mode 100644 index 0000000..2594944 --- /dev/null +++ b/pythonProject/login.py @@ -0,0 +1,57 @@ +from tkinter import * + +user_login = { + 'aaa': '123', + 'bbb': '654' +} + +count = 0 + +def temp(s): + win = Tk() + win.geometry('100x100') + + message = Label(win, text=s) + message.pack() + +def login() : + global count + username = entry_username.get() + if username not in user_login: + label_message.config(text='账号错误') + else: + password = entry_password.get() + if password == user_login[username]: + #label_message.config(text='登录成功') + temp('登录成功') + + else: + label_message.config(text='密码错误!还可以尝试{}次'.format(2 - count)) + count += 1 + if count == 3: + temp('登陆失败') + btn_login.config(state='disabled') + +windon = Tk() +windon.title('用户登录') +windon.geometry('300x200') + +label_username = Label(windon, text='账号') +label_username.pack() + +entry_username = Entry(windon) +entry_username.pack() + +label_password = Label(windon, text='密码') +label_password.pack() + +entry_password = Entry(windon, show='*') +entry_password.pack() + +btn_login = Button(windon, text='登录', command=login) +btn_login.pack() + +label_message = Label(windon, text="") +label_message.pack() + +windon.mainloop() diff --git a/pythonProject/test.py b/pythonProject/test.py new file mode 100644 index 0000000..5376f0b --- /dev/null +++ b/pythonProject/test.py @@ -0,0 +1,34 @@ +import requests +from lxml import etree + +url = 'https://www.maoyan.com/board/4?offset=0' + + + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0' +} + +response = requests.get(url=url, headers=headers) + +tree = etree.HTML(response.text) + +titles = tree.xpath('/html/body/div[4]/div/div/div[1]/dl/dd/div/div/div[1]/p[1]/a/text()') +actors = tree.xpath('/html/body/div[4]/div/div/div[1]/dl/dd/div/div/div[1]/p[2]/text()') +times = tree.xpath('/html/body/div[4]/div/div/div[1]/dl/dd/div/div/div[1]/p[3]/text()') + +items = [] + +for i in range(len(titles)): + title = titles[i].strip() + actors = actors[i].strip() + times = times[i].strip() + + items.append({ + 'title': titles, + 'actor': actors[3:], + 'time': times[5:] + }) + +for i in items: + print(i) \ No newline at end of file