parent
72d5ac23d4
commit
b73d6a0fba
@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.12 (pythonProject)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12 (pythonProject)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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)
|
@ -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()
|
@ -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)
|
Loading…
Reference in new issue