commit_0527

main
dqs2956213868 6 months ago
parent 478b08d462
commit 22ec0fd929

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -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 (PythonRequest01)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (PythonRequest01)" 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/PythonRequest01.iml" filepath="$PROJECT_DIR$/.idea/PythonRequest01.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_INTERACTIVE_PLOTS_SUGGESTED" value="true" />
</component>
</project>

@ -0,0 +1,48 @@
import jieba
import numpy
from PIL import Image
from wordcloud import WordCloud
import matplotlib.pyplot as plt
txt = open("../CommentRequest//评论.txt", "r", encoding='utf-8').read()
words = " ".join(list(jieba.cut(txt)))
counts = {}
# 停用词表设置
stopwords = [i.strip() for i in open("../Text/stopwords.txt", encoding='utf-8').readlines()]
for word in words:
if len(word) == 1:
continue
else:
# 遍历所有词语,每出现一次其对应的值加 1
counts[word] = counts.get(word, 0) + 1
items = list(counts.items())
# 根据词语出现的次数进行从大到小排序
items.sort(key=lambda x: x[1], reverse=True)
mask = numpy.array(Image.open("../image/bg2.png"))
wordcloud = WordCloud(font_path='../image/SimHei.ttf',
width=800,
height=400,
background_color='white',
mode='RGBA',
max_words=150,
stopwords=stopwords,
# mask=mask
).generate(words)
# 显示词云图
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.title('', fontproperties='SimHei')
plt.axis('off') # 不显示坐标轴
plt.show()

@ -0,0 +1,22 @@
from bs4 import BeautifulSoup
soup = BeautifulSoup(open('电影评论.html',encoding='utf-8'),'lxml')
# 获取节点内容
tags_with_class = soup.find_all(class_='review-content clearfix')
text_list = []
# 遍历结果集中的每个标签对象,并获取其文本内容
for tag in tags_with_class:
text_list.append(tag.text)
# 将列表转换为字符串
result_text = '\n'.join(text_list)
# 打印文本内容
print(result_text)
with open('评论.txt', 'w', encoding='utf-8') as fp:
fp.write(result_text)

@ -0,0 +1,37 @@
import urllib.request
url = 'https://movie.douban.com/review/1627740/'
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Cookie": 'll="118276"; bid=aRJ3WyvegZU; viewed="26979890"; ap_v=0,6.0',
"Host": "movie.douban.com",
"Referer": "https://movie.douban.com/subject/1308807/",
"Sec-Ch-Ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"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"
}
# (1) 请求对象的定制
request = urllib.request.Request(url, headers=headers)
# (2)获取响应的数据
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
# 和上面的代码一样
with open('电影评论.html', 'w', encoding='utf-8') as fp:
fp.write(content)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

@ -0,0 +1,72 @@
import tkinter as tk
from tkinter import messagebox
# 示例数据
items = [f"项目 {i + 1}" for i in range(50)]
# 定义搜索函数
def search_items():
search_term = entry_search.get().lower()
matches = [item for item in items if search_term in item.lower()]
if matches:
open_results_page(matches)
else:
messagebox.showinfo("搜索结果", "没有找到匹配的项目。")
# 定义显示搜索结果的函数
def open_results_page(matches):
results_window = tk.Toplevel(root)
results_window.title("搜索结果")
results_window.geometry("300x200")
label_results = tk.Label(results_window, text="搜索结果:", font=("Arial", 12))
label_results.pack(pady=10)
listbox_results = tk.Listbox(results_window, width=40, height=10)
listbox_results.pack()
for match in matches:
listbox_results.insert(tk.END, match)
# 创建主应用程序窗口
root = tk.Tk()
root.title("搜索框示例")
root.geometry("300x300")
# 创建搜索框标签和输入框
label_search = tk.Label(root, text="搜索:")
label_search.pack(pady=5)
entry_search = tk.Entry(root)
entry_search.pack(pady=5)
# 创建搜索按钮
btn_search = tk.Button(root, text="搜索", command=search_items)
btn_search.pack(pady=5)
# 创建一个框架来包含列表框和滚动条
frame = tk.Frame(root)
frame.pack(pady=20)
# 创建一个列表框
listbox = tk.Listbox(frame, width=40, height=10)
listbox.pack(side=tk.LEFT)
# 创建一个滚动条
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# 将滚动条与列表框关联
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
# 向列表框中添加初始项目
for item in items:
listbox.insert(tk.END, item)
# 运行主循环
root.mainloop()

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Loading…
Cancel
Save