diff --git a/pythonProject1/.idea/.gitignore b/pythonProject1/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/pythonProject1/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/pythonProject1/.idea/misc.xml b/pythonProject1/.idea/misc.xml new file mode 100644 index 0000000..5885df1 --- /dev/null +++ b/pythonProject1/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/pythonProject1/.idea/modules.xml b/pythonProject1/.idea/modules.xml new file mode 100644 index 0000000..fdd8fdf --- /dev/null +++ b/pythonProject1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pythonProject1/.idea/pythonProject1.iml b/pythonProject1/.idea/pythonProject1.iml new file mode 100644 index 0000000..79f77b6 --- /dev/null +++ b/pythonProject1/.idea/pythonProject1.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pythonProject1/TrialRecommend/DataRequest.py b/pythonProject1/TrialRecommend/DataRequest.py new file mode 100644 index 0000000..cf50f49 --- /dev/null +++ b/pythonProject1/TrialRecommend/DataRequest.py @@ -0,0 +1,111 @@ +import csv +import random +from DrissionPage import ChromiumOptions +from DrissionPage import ChromiumPage +import time + +path=r"C:\Program Files\Google\Chrome\Application\chrome.exe" +ChromiumOptions().set_browser_path(path).save() + +class DataRequest: + def __init__(self,keyword): + #创建文件对象 + self.success='False' + self.resp = None + self.data_csv_file_path= 'data.csv' + self.notes_csv_file_path= 'notes.csv' + #初始化 清空文档 + self.clear_csv_file() + self.f=open('data.csv', mode='a+', encoding='utf-8', newline='') + self.csv_writer=csv.DictWriter(self.f,fieldnames=['文章ID','文章标题','喜欢数量','图片资源']) + # + self.keyword=keyword + self.url='https://www.xiaohongshu.com/search_result?keyword='+self.keyword+'&type=51' + #数据 + self.items=[] + #打开浏览器 + self.drive=ChromiumPage() + self.drive.set.scroll.smooth(on_off=True) + self.drive.set.scroll.wait_complete(on_off=True) + # 监听数据报 + self.drive.listen.start('api/sns/web/v1/search/notes') + #访问网站 + self.drive.get(self.url) + self.dataRequest() + + def clear_csv_file(self): + with open(self.data_csv_file_path, 'w') as file1: # 使用'w'模式打开文件 + pass # 不需要执行任何操作,因为打开文件时内容已被清空 + with open(self.notes_csv_file_path,'w') as file2: + pass # 不需要执行任何操作,因为打开文件时内容已被清空 + + def dataRequest(self): + #滚动到底部刷新数据包 + self.drive.scroll.to_bottom() + #等待数据包加载 + self.resp=self.drive.listen.wait() + #获取数据包返回的数据 + json_data=self.resp.response.body + + #分析数据放入容器 + for item in json_data['data']['items']: + if '-' not in item['id']: + if 'display_title' in item['note_card']: + self.success = 'True' + time_Images=[] + for image_list in item['note_card']['image_list']: + time_Images.append(image_list['info_list'][0]['url']) + + dic={ + '文章ID':item['id'], + '文章标题':item['note_card']['display_title'], + '喜欢数量':item['note_card']['interact_info']['liked_count'], + '图片资源':time_Images + } + self.items.append(dic) + else: + self.success = 'False' + break + if self.success == 'True': + self.sort() + self.check() + + def is_in_csv(self,data_to_check): + with open(self.data_csv_file_path,'r',encoding='utf-8') as f: + csv_reader=csv.reader(f) + for row in csv_reader: + if data_to_check in row: + return True + return False + + def sort(self): + #按照喜欢人数排序 + self.items.sort(key=lambda item:int(item['喜欢数量']),reverse=True) + for i in self.items: + if self.is_in_csv(i['文章ID']): + continue + else: + self.csv_writer.writerow(i) + + def close(self): + self.drive.listen.stop() + self.f.close() + def check(self): + with open('data.csv', mode='r', encoding='utf-8') as file: + for line in file: + if line==None: + print('数据获取失败') + break + else: + print('数据获取成功') + break + + # print('[1]:',line.split(',')[1]) + # break + +if __name__=='__main__': + dataRequest=DataRequest('厦门旅游攻略') + for i in range(1): + dataRequest.dataRequest() + time.sleep(random.randint(3,4)) + diff --git a/pythonProject1/TrialRecommend/LoginCheck.py b/pythonProject1/TrialRecommend/LoginCheck.py new file mode 100644 index 0000000..b08d1da --- /dev/null +++ b/pythonProject1/TrialRecommend/LoginCheck.py @@ -0,0 +1,28 @@ +import mysql.connector +class Login_check(): + db=mysql.connector.connect( + host="localhost", + user="root", + passwd="A121023020309a", + database="trial" + ) + # 创建游标对象,用于执行SQL查询 + cursor = db.cursor() + @classmethod + def check(self,id,psw): + sql = "SELECT * FROM user WHERE id = %s AND psw = %s" + self.cursor.execute(sql,(id,psw)) + # 获取查询结果 + results = self.cursor.fetchall() + for row in results: + if id==row[0] and psw==row[1]: + return True + return False + @classmethod + def close(self): + self.cursor.close() # 关闭游标 + print('游标已关闭') + self.db.close() # 关闭数据库连接 + print('数据库已关闭') + +login_check = Login_check() \ No newline at end of file diff --git a/pythonProject1/TrialRecommend/LoginPage.py b/pythonProject1/TrialRecommend/LoginPage.py new file mode 100644 index 0000000..9992ee9 --- /dev/null +++ b/pythonProject1/TrialRecommend/LoginPage.py @@ -0,0 +1,58 @@ +import tkinter as tk +from tkinter import messagebox +from TrialRecommend.LoginCheck import login_check +from Main import Mainpage + +class Login_page(): + + def __init__(self,master): + self.data_csv_file_path='data.csv' + self.notes_csv_file_path='notes.csv' + self.root=master + self.username = tk.StringVar() + self.password = tk.StringVar() + self.page=tk.Frame(self.root) + self.page.pack() + + tk.Label(self.page).grid(row=0, column=0) + tk.Label(self.page,text='账户:').grid(row=1, column=1,pady=10) + tk.Entry(self.page,textvariable=self.username).grid(row=1, column=2) + tk.Label(self.page, text='密码:').grid(row=2, column=1,pady=10) + tk.Entry(self.page,textvariable=self.password,show='*').grid(row=2, column=2) + tk.Button(self.page,text='登录',command=self.check).grid(row=3, column=1,pady=10) + tk.Button(self.page,text='退出',command=self.page.quit).grid(row=3, column=3,pady=10) + self.center_window() # 调用函数来居中窗口 + self.root.title('旅游推荐系统登录界面') + + def check(self): + name = self.username.get() + psw = self.password.get() + if login_check.check(name, psw): + messagebox.showinfo(title='提示', message='登录成功') + self.page.destroy() + Mainpage(self.root,name) + else: + messagebox.showwarning(title='警告', message='用户名或密码错误') + def center_window(self, width=400, height=200): + # 获取屏幕宽度和高度 + screen_width = self.root.winfo_screenwidth() + screen_height = self.root.winfo_screenheight() + + # 计算窗口的左上角应该放置的位置 + left = (screen_width / 2) - (width / 2) + top = (screen_height / 2) - (height / 2) + + # 设置窗口的位置和大小 + root.geometry("{0}x{1}+{2}+{3}".format(width, height, int(left), int(top))) + + def clear_csv_file(self): + with open(self.data_csv_file_path, 'w') as file1: # 使用'w'模式打开文件 + pass # 不需要执行任何操作,因为打开文件时内容已被清空 + with open(self.notes_csv_file_path, 'w') as file2: + pass # 不需要执行任何操作,因为打开文件时内容已被清空 + +if __name__ == '__main__': + root = tk.Tk() + login=Login_page(root) + root.mainloop() + login.clear_csv_file() \ No newline at end of file diff --git a/pythonProject1/TrialRecommend/Main.py b/pythonProject1/TrialRecommend/Main.py new file mode 100644 index 0000000..bf72080 --- /dev/null +++ b/pythonProject1/TrialRecommend/Main.py @@ -0,0 +1,396 @@ +import csv +import random +import time +import tkinter as tk +from io import BytesIO +from tkinter import messagebox + +import requests +from PIL import Image, ImageTk +from TrialRecommend import DataRequest, Notes_Request + +import func_collec +class Mainpage: + def __init__(self,master,name): + self.content = '' + self.time = '' + self.collect = '' + self.likes = '' + self.share = '' + + self.flag = 0 + self.is_pre = 'False' + + self.current_data_index = 0 + self.current_data_image_index = 0 + self.current_notes_index = 0 + self.max_data_count = 0 + self.max_notes_count = 0 + self.max_iamge_count = 0 + + self.data_csv_file_path = 'data.csv' + self.notes_csv_file_path = 'notes.csv' + self.data_request = None + self.research = tk.StringVar() + self.user = name + self.root = master + self.root.title('推荐中心 v0.0.1') + # 调用函数来居中窗口 + self.center_window(self.root) + self.init_main_Page() + + def init_main_Page(self): + self.page = tk.Frame(self.root) + self.page.place(relx=0, rely=0, relheight=1, relwidth=1) + + + self.btn_exit = tk.Button(self.page, text='退出', command=self.exit, bg='#D7EFFF', fg='red',font='bold') + self.btn_exit.place(relx=0.9, rely=0.9, relheight=0.05, relwidth=0.07) + + self.lable_user = tk.Label(self.page, text='欢迎您:' + self.user, fg='green', font=24) + self.lable_user.place(relx=0.86, rely=0, relheight=0.08, relwidth=0.13) + + self.text = tk.Text(self.page, bg='#ADD9FE', font=18) + self.text.insert(tk.END, self.content) + self.text.config(state=tk.DISABLED, cursor='') + self.text.place(relx=0.58, rely=0.07, relheight=0.86, relwidth=0.3) + + self.btn_Image_pre=tk.Button(self.page,text='上一张',bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.pre_image) + self.btn_Image_pre.place(relx=0.14, rely=0.01, relheight=0.05, relwidth=0.07) + + self.btn_Image_next = tk.Button(self.page, text='下一张', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.next_image) + self.btn_Image_next.place(relx=0.24, rely=0.01, relheight=0.05, relwidth=0.07) + + self.btn_liked_page = tk.Button(self.page, text='我的收藏夹', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.to_like_page) + self.btn_liked_page.place(relx=0.9, rely=0.1, relheight=0.05, relwidth=0.1) + + self.btn_next = tk.Button(self.page, text='下一篇', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.next_data) + self.btn_next.place(relx=0.45, rely=0.45, relheight=0.08, relwidth=0.09) + + self.btn_pre = tk.Button(self.page, text='上一篇', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.back_data) + self.btn_pre.place(relx=0.45, rely=0.35, relheight=0.08, relwidth=0.09) + + self.btn_liked = tk.Button(self.page, text='收藏攻略', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.func_collect) + self.btn_liked.place(relx=0.9, rely=0.2, relheight=0.05, relwidth=0.1) + + self.btn_dis_liked = tk.Button(self.page, text='取消收藏', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_dis_liked.place(relx=0.9, rely=0.3, relheight=0.05, relwidth=0.1) + + self.lable_like=tk.Label(self.page,text='喜欢人数:'+self.likes,font=('SimHei',15,'bold')) + self.lable_like.place(relx=0.05, rely=0.93) + + self.lable_like = tk.Label(self.page, text='收藏人数:'+self.collect,font=('SimHei',15,'bold')) + self.lable_like.place(relx=0.17, rely=0.93) + + self.lable_like = tk.Label(self.page, text='转发人数:'+self.share,font=('SimHei',15,'bold')) + self.lable_like.place(relx=0.29, rely=0.93) + + self.entry=tk.Entry(self.page,textvariable=self.research,font=('',20, "bold")) + self.entry.place(relx=0.35, rely=0.01, relheight=0.05, relwidth=0.3) + + self.btn_research=tk.Button(self.page,text='搜索', bg='#D7EFFF',font=("SimHei",20, "bold"),command=self.researchPage) + self.btn_research.place(relx=0.66, rely=0.01, relheight=0.05, relwidth=0.1) + + self.lable_time=tk.Label(self.page,text='发布时间:'+self.time,font=('SimHei',15,'bold')) + self.lable_time.place(relx=0.41, rely=0.93) + + def to_init_page(self): + self.page2.destroy() + self.init_text() + self.init_main_Page() + self.update_max() + self.image_url(self.current_data_index, self.current_data_image_index) + def to_like_page(self): + self.page.destroy() + self.init_like_page() + + def init_like_page(self): + self.page2=tk.Frame(self.root) + self.page2.place(relx=0,rely=0,relheight=1,relwidth=1) + + self.btn_init_page = tk.Button(self.page2, text='返回主页面',command=self.to_init_page, bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_init_page.place(relx=0.9, rely=0.1, relheight=0.05, relwidth=0.1) + + self.lable_user = tk.Label(self.page2, text='欢迎您:' + self.user, fg='green', font=24) + self.lable_user.place(relx=0.86, rely=0, relheight=0.08, relwidth=0.13) + + self.btn_exit = tk.Button(self.page2, text='退出', command=self.exit, bg='#D7EFFF', fg='red',font='bold') + self.btn_exit.place(relx=0.9, rely=0.9, relheight=0.05, relwidth=0.07) + + self.text = tk.Text(self.page2, bg='#ADD9FE', font=18) + self.text.insert(tk.END, '收藏页面') + self.text.config(state=tk.DISABLED, cursor='') + self.text.place(relx=0.58, rely=0.07, relheight=0.86, relwidth=0.3) + + self.btn_Image_pre = tk.Button(self.page2, text='上一张', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_Image_pre.place(relx=0.14, rely=0.01, relheight=0.05, relwidth=0.07) + + self.btn_Image_next = tk.Button(self.page2, text='下一张', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_Image_next.place(relx=0.24, rely=0.01, relheight=0.05, relwidth=0.07) + + self.btn_next = tk.Button(self.page2, text='下一篇', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_next.place(relx=0.45, rely=0.45, relheight=0.08, relwidth=0.09) + + self.btn_pre = tk.Button(self.page2, text='上一篇', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_pre.place(relx=0.45, rely=0.35, relheight=0.08, relwidth=0.09) + + self.btn_liked = tk.Button(self.page2, text='收藏攻略', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_liked.place(relx=0.9, rely=0.2, relheight=0.05, relwidth=0.1) + + self.btn_dis_liked = tk.Button(self.page2, text='取消收藏', bg='#D7EFFF',font=('SimHei',15,'bold')) + self.btn_dis_liked.place(relx=0.9, rely=0.3, relheight=0.05, relwidth=0.1) + + self.lable_like = tk.Label(self.page2, text='喜欢人数:', font=('SimHei',15,'bold')) + self.lable_like.place(relx=0.05, rely=0.93) + + self.lable_like = tk.Label(self.page2, text='收藏人数:', font=('SimHei',15,'bold')) + self.lable_like.place(relx=0.17, rely=0.93) + + self.lable_like = tk.Label(self.page2, text='转发人数:', font=('SimHei',15,'bold')) + self.lable_like.place(relx=0.29, rely=0.93) + def notes_request(self,next_back): + if next_back == 'next': + if self.current_data_index + 1 <= self.max_data_count: + with open('data.csv', 'r', encoding='utf-8') as f: + if self.current_notes_index!=self.flag: + self.current_notes_index += 1 + self.current_data_index += 1 + else: + self.current_notes_index += 1 + self.current_data_index += 1 + self.flag=self.current_notes_index + csv_reader = csv.reader(f) + data='' + i=0 + for row in csv_reader: + if i == self.current_data_index: + data = row[0] + break + i += 1 + if self.is_pre=='False': + Notes_Request.notes_request(data) + if self.flag==self.current_notes_index: + self.is_pre='False' + time.sleep(random.uniform(0, 1)) + self.update_max() + print(self.max_data_count, self.current_data_index, self.current_data_image_index) + self.init_text() + self.init_main_Page() + self.image_show() + else: + messagebox.showinfo(message='正在载入新的一批数据,请稍等!') + self.data_request.dataRequest() + if self.data_request.success == 'True': + time.sleep(random.uniform(1, 2)) + with open('data.csv', 'r', encoding='utf-8') as f: + if self.current_notes_index != self.flag: + self.current_notes_index += 1 + self.current_data_index += 1 + else: + self.current_notes_index += 1 + self.current_data_index += 1 + self.flag = self.current_notes_index + csv_reader = csv.reader(f) + data='' + i=0 + for row in csv_reader: + if i == self.current_data_index: + data = row[0] + i += 1 + if self.is_pre == 'False': + Notes_Request.notes_request(data) + if self.flag == self.current_notes_index: + self.is_pre = 'True' + time.sleep(random.uniform(0, 1)) + self.update_max() + print(self.max_data_count, self.current_data_index, self.current_data_image_index) + self.init_text() + self.init_main_Page() + self.image_show() + else: + messagebox.showinfo(message='网络请求失败,请稍后尝试!') + + if next_back == 'back': + if self.current_notes_index-1<0: + messagebox.showinfo(message='这是第一篇文章') + else: + self.is_pre = 'True' + self.current_notes_index -= 1 + self.current_data_index -= 1 + with open('data.csv', 'r', encoding='utf-8') as f: + csv_reader = csv.reader(f) + first_row = '' + i=0 + for row in csv_reader: + if i==self.current_data_index: + first_row=row[0] + i += 1 + Notes_Request.notes_request(first_row) + time.sleep(random.uniform(0, 1)) + self.update_max() + print(self.max_data_count, self.current_data_index, self.current_data_image_index) + self.init_text() + self.init_main_Page() + self.image_show() + # 返回上一篇 + def back_data(self): + if self.max_data_count != 0: + self.current_data_image_index = 0 + self.notes_request('back') + else: + messagebox.showinfo(message='请先搜索') + # 下一篇 + def next_data(self): + if self.max_data_count != 0: + self.current_data_image_index = 0 + self.notes_request('next') + else: + messagebox.showinfo(message='请先搜索') + # 下一张图片 + def next_image(self): + + if self.max_iamge_count == 0: + messagebox.showinfo(message='请先搜索') + elif self.current_data_image_index + 1 >= self.max_iamge_count: + messagebox.showinfo(message='这是最后一张') + else: + self.current_data_image_index += 1 + self.image_url(self.current_data_index, self.current_data_image_index) + # 上一张图片 + def pre_image(self): + if self.max_iamge_count == 0: + messagebox.showinfo(message='请先搜索') + elif self.current_data_image_index - 1 < 0: + messagebox.showinfo(title='提示', message='没有上一张了') + else: + self.current_data_image_index -= 1 + self.image_url(self.current_data_index, self.current_data_image_index) + def researchPage(self): + self.clear_csv_file() + rs=self.research.get() + if rs=='': + messagebox.showinfo(title='提示', message='你还没有输入任何东西!') + else: + if DataRequest.DataRequest(str(self.research.get())).success=='True': + self.data_request = DataRequest.DataRequest(str(self.research.get())) + time.sleep(random.uniform(0,1)) + self.init_notes_request() + else: + messagebox.showinfo(message='网络请求失败,请稍后尝试!') + def init_notes_request(self): + with open('data.csv', 'r', encoding='utf-8') as f: + reader = csv.reader(f) + for row in reader: + Notes_Request.notes_request(row[0]) + break + self.update_max() + self.init_text() + self.init_main_Page() + self.image_show() + def image_url(self,index,col): + with open(self.data_csv_file_path,'r',encoding='utf-8') as f: + reader = csv.reader(f) + row ='' + i=0 + for rows in reader: + if i==self.current_data_index: + row=rows + i += 1 + self.load_image_from_url(self.page,eval(row[3])[col]) + def load_image_from_url(self,View,url): + # 使用requests从URL下载图片 + response = requests.get(url) + img = Image.open(BytesIO(response.content)) + img = img.resize((450, 600), Image.BICUBIC) # 调整像素,使用高质量重采样算法 + # 使用PIL的ImageTk将PIL图片转换为Tkinter可以显示的格式 + tk_img = ImageTk.PhotoImage(img) + + # 创建一个标签来显示图片,并添加到Tkinter窗口中 + label = tk.Label(View, image=tk_img) + label.image = tk_img # 保持对tk_img的引用,防止被垃圾回收 + label.place(relx=0.05, rely=0.07) + def image_show(self): + if self.csv_is_empty(): + messagebox.showinfo('提示',message='数据加载失败') + else: + self.image_url(self.current_data_index,0) + def csv_is_empty(self): + with open('notes.csv','r',encoding='utf-8') as f2: + rows = [] + reader = csv.reader(f2) + for row in reader: + # 如果找到非空行,则将rows列表设置为非空 + if any(row): + rows.append(row) + return False # 如果只需要检查是否至少有一行非空,则可以提前退出循环 + # 如果rows列表为空,则CSV文件是空的(或只包含空行) + if len(rows) == 0: + print('notes 无数据') + return True + def init_text(self): + with open(self.notes_csv_file_path,'r',encoding='utf-8') as f: + reader = csv.reader(f) + index=0 + for row in reader: + if index==self.current_notes_index: + title = row[0] + text = row[1].replace('
', '\n').replace('.
', '') + self.content=title+text + self.time = row[2] + self.collect = row[3] + self.likes = row[4] + self.share = row[5] + index += 1 + def update_max(self): + with open(self.data_csv_file_path,'r',encoding='utf-8') as f: + reader = csv.reader(f) + index=0 + for row in reader: + if index==self.current_data_index: + self.max_iamge_count = len(eval(row[3])) + break + index+=1 + + with open(self.data_csv_file_path, 'r', encoding='utf-8') as f: + reader = csv.reader(f) + counts = 0 + for i in reader: + counts += 1 + self.max_data_count = counts + + with open(self.notes_csv_file_path,'r',encoding='utf-8') as f: + reader = csv.reader(f) + counts=0 + for i in reader: + counts+=1 + self.max_notes_count=counts + def clear_csv_file(self): + with open(self.data_csv_file_path, 'w') as file1: # 使用'w'模式打开文件 + pass # 不需要执行任何操作,因为打开文件时内容已被清空 + with open(self.notes_csv_file_path, 'w') as file2: + pass # 不需要执行任何操作,因为打开文件时内容已被清空 + def exit(self): + messagebox.showinfo(title='提示', message='欢迎下次使用!') + self.root.quit() + def center_window(self, root, width=1300, height=700): + # 获取屏幕宽度和高度 + screen_width = root.winfo_screenwidth() + screen_height = root.winfo_screenheight() + + # 计算窗口的左上角应该放置的位置 + left = (screen_width / 2) - (width / 2) + top = (screen_height / 2) - (height / 2) + + # 设置窗口的位置和大小 + root.geometry("{0}x{1}+{2}+{3}".format(width, height, int(left), int(top))) + + def func_collect(self): + if self.max_data_count!=0: + func_collec.collec(self.user, self.current_data_index) + else: + messagebox.showinfo('提示','请先搜索') + +if __name__ == '__main__': + root = tk.Tk() + Mainpage(master=root,name='Null') + root.mainloop() diff --git a/pythonProject1/TrialRecommend/Notes_Request.py b/pythonProject1/TrialRecommend/Notes_Request.py new file mode 100644 index 0000000..10df68f --- /dev/null +++ b/pythonProject1/TrialRecommend/Notes_Request.py @@ -0,0 +1,75 @@ +import json +import re +from csv import DictWriter, DictReader +import requests +from bs4 import BeautifulSoup + +def notes_request(url): + url='https://www.xiaohongshu.com/explore/'+url + headers = { + 'authority':'edith.xiaohongshu.com', + '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', + 'Content-Type':'text/html; charset=utf-8', + 'Origin':'https://www.xiaohongshu.com', + 'Referer':'https://www.xiaohongshu.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'} + cookies = { + 'abRequestId':'a3c8a855-ed85-57f6-91fe-3e0acedffde8', + 'a1':'18f9b67ecdbh41bri2la0dgguminrd7dmmrk4pxf750000215521', + 'webId':'6d97ebd3e6051489537e7a6aa1d1cf99', + 'gid':'yYijDKYydJ6JyYijDKWdS6UCfDx4yDF3J108FiWfkk763T28IFfWf4888Jy22Jy8WYf0SyjD', + 'webBuild':'4.16.1', + 'web_session':'040069b3643d32585fff79ee79344bd4b89bc6', + 'acw_tc':'25f299cc55249ae472ab6eab4f8404ce338ad4b4544c7f87a592375d787ede3a', + 'websectiga':'16f444b9ff5e3d7e258b5f7674489196303a0b160e16647c6c2b4dcb609f4134', + 'sec_poison_id':'9e6926ce-0bb8-4335-992a-0ec7875fff69', + 'xsecappid':'xhs-pc-web' + + } + f=open('notes.csv', mode='a+', encoding='utf-8', newline='') + csv_writer=DictWriter(f,fieldnames=['标题','内容','发布时间','收藏数','喜欢数','分享数']) + + response = requests.get(url=url, headers=headers, cookies=cookies) + soup = BeautifulSoup(response.text, 'lxml') + long_string=soup.prettify() + pattern = r'"interactInfo":{[^}]*}' + match = re.search(pattern, long_string) + js=match.group(0)[15:] + #将字符串转化为字典 + data_dict = json.loads(js) + + if '请输入验证码' in soup.text: + print('需要输入验证码或更新Cookie') + else: + title = soup.find('title').text + publish_time = soup.find('span', class_='date').text + collectedCount=data_dict['collectedCount'] + likedCount=data_dict['likedCount'] + shareCount=data_dict['shareCount'] + # 找到目标div并获取其所有内容(包括
标签) + desc_div = soup.find('div', class_='desc') + # 使用正则表达式匹配标签内的文本 + match = re.findall(r']*="">.*?<\/span>', str(desc_div.contents)) + if match: + for text_inside in match: + if ' 'not in text_inside and len(text_inside)>50 and 'class="note-content-user"' not in text_inside: + pattern = r'="">(.*?)<\/span>' + text_inside = re.findall(pattern, text_inside) + dic={ + '标题':title.replace('- 小红书',''), + '内容':text_inside[0], + '发布时间':publish_time, + '收藏数':collectedCount, + '喜欢数':likedCount, + '分享数':shareCount + } + csv_writer.writerow(dic) + print('笔记拉取成功') + break + + f.close() + + +if __name__ == '__main__': + notes_request('654a541e000000001e029a6a') diff --git a/pythonProject1/TrialRecommend/__pycache__/DataRequest.cpython-312.pyc b/pythonProject1/TrialRecommend/__pycache__/DataRequest.cpython-312.pyc new file mode 100644 index 0000000..567898c Binary files /dev/null and b/pythonProject1/TrialRecommend/__pycache__/DataRequest.cpython-312.pyc differ diff --git a/pythonProject1/TrialRecommend/__pycache__/LoginCheck.cpython-312.pyc b/pythonProject1/TrialRecommend/__pycache__/LoginCheck.cpython-312.pyc new file mode 100644 index 0000000..639ad86 Binary files /dev/null and b/pythonProject1/TrialRecommend/__pycache__/LoginCheck.cpython-312.pyc differ diff --git a/pythonProject1/TrialRecommend/__pycache__/Main.cpython-312.pyc b/pythonProject1/TrialRecommend/__pycache__/Main.cpython-312.pyc new file mode 100644 index 0000000..e61384b Binary files /dev/null and b/pythonProject1/TrialRecommend/__pycache__/Main.cpython-312.pyc differ diff --git a/pythonProject1/TrialRecommend/__pycache__/Notes_Request.cpython-312.pyc b/pythonProject1/TrialRecommend/__pycache__/Notes_Request.cpython-312.pyc new file mode 100644 index 0000000..81ea7b4 Binary files /dev/null and b/pythonProject1/TrialRecommend/__pycache__/Notes_Request.cpython-312.pyc differ diff --git a/pythonProject1/TrialRecommend/__pycache__/func_collec.cpython-312.pyc b/pythonProject1/TrialRecommend/__pycache__/func_collec.cpython-312.pyc new file mode 100644 index 0000000..1204368 Binary files /dev/null and b/pythonProject1/TrialRecommend/__pycache__/func_collec.cpython-312.pyc differ diff --git a/pythonProject1/TrialRecommend/data.csv b/pythonProject1/TrialRecommend/data.csv new file mode 100644 index 0000000..17a1ef2 --- /dev/null +++ b/pythonProject1/TrialRecommend/data.csv @@ -0,0 +1,10 @@ +649816f8000000001303d732,第一次去株洲买衣服 500元买了9件,5972,"['http://sns-webpic-qc.xhscdn.com/202405262335/10a80751f1f8f599e44b2d911a215b44/1000g0082n0s5vlojk000459240k8dgvg8pknqig!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/d07a643f315fa9d6731a123afc59ed18/1000g0082n0s5vlojk00g459240k8dgvg2q77008!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/0fa74130e4c8740a871379e72eb578f1/1000g0082n0s5vlojk010459240k8dgvgps7eb08!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/f8e5586ec8cd802ee3d5b37f827b33e3/1000g0082n0s5vlojk01g459240k8dgvgbm33rig!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/35e9a9ec61c898a0b0133b653dc5a370/1000g0082n0s5vlojk020459240k8dgvgtjg2ndg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/b33d3a4e096fea298082d7a3d2b7dfd0/1000g0082n0s5vlojk02g459240k8dgvguio2lmo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/90210a78b871978113c37b0f2a83fd94/1000g0082n0s5vlojk030459240k8dgvgfkb7dkg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/97239eda30fa88230f4eae28a7ea162c/1000g0082n0s5vlojk03g459240k8dgvgi58hvf0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/bc32ada154d1a795798e17d6af6e0cab/1000g0082n0s5vlojk040459240k8dgvgqinob9g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a88a59cf6074143d53eacd5d5e621db5/1000g0082n0s5vlojk04g459240k8dgvgmabf1i8!nc_n_webp_mw_1']" +651d65bc000000001f0053aa,株洲敲适合city walk的一条街🍂好逛又好拍,5933,['http://sns-webpic-qc.xhscdn.com/202405262335/70694052ba78a3d03dc1044790d07dd3/1040g00830pqcsrro6q004a6p01vkmfuo2j12u3g!nc_n_webp_mw_1'] +6586f4110000000038015027,长沙周边游 | 株洲两日攻略(附详细景点介绍,2076,"['http://sns-webpic-qc.xhscdn.com/202405262335/395bb31308f002d95326ea701a535e10/1040g2sg30t1fh5u63u005p7lmaf18113ig1pqu8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/b183e342c418b0a6a2b0570e02eb892d/1040g2sg30t1fh5u63u0g5p7lmaf18113bo892m0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/b11cdf41ab6367749411d7a3d1abcbb4/1040g2sg30t1fh5u63u105p7lmaf181130s31f1g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/5c53162ad9402aeddabca72657e56967/1040g2sg30t1fh5u63u1g5p7lmaf18113225kl4g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/e2cdc30025df9eb30baa44708d967c93/1040g2sg30t1fh5u63u205p7lmaf18113n35f1tg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/b3011765ae37806b85364430fe4be7c8/1040g2sg30t1fh5u63u2g5p7lmaf18113clbr86o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/96b115f6fff94703e286037fa61318e7/1040g2sg30t1fh5u63u305p7lmaf18113k3ha4eo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/c363fb23288406f0ee8ab9732b5afb98/1040g2sg30t1fh5u63u3g5p7lmaf18113v7otgeo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/651f3738f0b88d78f6cb937b9e3d0b61/1040g2sg30t1fh5u63u405p7lmaf18113sena380!nc_n_webp_mw_1']" +662884050000000003020521,株洲一日攻略丨特种兵女大Citywalk路线‼️,1778,"['http://sns-webpic-qc.xhscdn.com/202405262335/428a204b96f96669cc3f314adb7fb2a5/1040g2sg311v8bf9530005o7k5p908v0jkougld8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/1d50c2c65ae7108df2e18491a999be77/1040g2sg311v8bf95300g5o7k5p908v0js69da70!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/bb40b9a88902c506cfd4e500a9c1a24f/1040g2sg311v8bf9530105o7k5p908v0jge8dbc0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/335bdc09e2311717420f77eb320f41bc/1040g2sg311v8bf95301g5o7k5p908v0ji3ha00g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/2902f99fe4dadcaee2e417b0a07d3233/1040g2sg311v8bf9530205o7k5p908v0jlkbr0to!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/6157fc5d53ff4acf1bc24a18ad94cdb8/1040g2sg311v8bf95302g5o7k5p908v0jtdpm07o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/c1ddee3eab5b7f22d3a4f417ab97f169/1040g2sg311v8bf9530305o7k5p908v0jln7i45g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/5793d05adc527d50ce79df7f563f081f/1040g2sg311v8bf95303g5o7k5p908v0jhh2bn00!nc_n_webp_mw_1']" +657ffbb7000000000703920c,株洲也有自己的文艺巷子啦✨🐕🌸,1187,"['http://sns-webpic-qc.xhscdn.com/202405262335/18400596f57c263fad2b163d1dfc98d1/1040g2sg30sqlmci742004a7mjb6ciub7g76m89o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/9d82dd20d550686890bda86c559934f3/1040g2sg30sqlmci7420g4a7mjb6ciub7fngip78!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/7c96d86a4a0f2141229fc35623635288/1040g2sg30sqlmci742104a7mjb6ciub7rh9iqo8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/2ff41d5b7135ad897ff3a9fb3b3c121a/1040g2sg30sqlmci7421g4a7mjb6ciub7baok04o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/c3e76764c44c5bd13ac73b0ae3edff38/1040g2sg30sqlmci742204a7mjb6ciub79glsnqg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/f087c6d4e1df2a24df2e32494ab3a3f0/1040g2sg30sqlmci7422g4a7mjb6ciub7pkbuc3o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/85c4c4943386806e3a83a98fffae2c96/1040g2sg30sqlmci742304a7mjb6ciub7a3ps9ag!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/5481ee0b8c16864214cc75484343050c/1040g2sg30sqlmci7423g4a7mjb6ciub7dpaqnso!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/3d8f6e626fb13db91263b7862ac5de39/1040g2sg30sqlmci742404a7mjb6ciub72sp2v08!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/7a1333d66963425e5219fa31d4dfaef0/1040g2sg30sqlmci7424g4a7mjb6ciub7vmqm0q8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/6055f8ee87a15d8de91316ba23949ddb/1040g2sg30sqlmci742504a7mjb6ciub716m96m8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/c4e35027c8f5f309d204d6afc0980bd8/1040g2sg30sqlmci7425g4a7mjb6ciub79gcr1qg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/bf220ad342583b09e70ad35d247f2fc0/1040g2sg30sqlmci742604a7mjb6ciub730jga5g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/feefad20bca85ca3582a1d1f027a5e4b/1040g2sg30sqlmci7426g4a7mjb6ciub7u9kac1g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/0777eca1460336c797a654635de3413a/1040g00830sqlmcknk2004a7mjb6ciub7gs08if8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/5f8b6ef281dc95ca4dc675a1bded5de3/1040g00830sqlmcknk20g4a7mjb6ciub78nbr2n0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/7ddbee0cbab7f7bccd7859b53d071f1d/1040g00830sqlmcknk2104a7mjb6ciub7r52a0jg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a524968bd853dfccd2425a699a35ba4a/1040g00830sqlmcknk21g4a7mjb6ciub7a82i9h0!nc_n_webp_mw_1']" +663465cb000000001e01af52,长沙到株洲买衣服攻略!!,958,"['http://sns-webpic-qc.xhscdn.com/202405262335/81e6773e4544131792ead7556f158599/1040g2sg312arlbq1lm005nhdo5mg8svbul2co58!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/864c295d9138ab6b669b964efbf1531e/1040g2sg312arlbq1lm0g5nhdo5mg8svb6e9s8c8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/1b73bc27c0626b95a76f5caa96386f4e/1040g2sg312arlbq1lm105nhdo5mg8svbft2e5ng!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/556d1240a6d77d135e30f347ca4830b5/1040g2sg312arlbq1lm1g5nhdo5mg8svb8fck3j0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/0af044295b4d21035ec850966b07590a/1040g2sg312arlbq1lm205nhdo5mg8svbr21qkoo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/68b6531f57fd77e6af621568eedae679/1040g2sg312arlbq1lm2g5nhdo5mg8svbubbhstg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/1dd55adcbd7154f36d159c2ee12fe709/1040g2sg312arlbq1lm305nhdo5mg8svb0k8flo0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/5126bcd39da1d31014aaba1c7bbc3929/1040g2sg312arlbq1lm3g5nhdo5mg8svbhsc5os8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/58856c29f8062649a41709222cb549b5/1040g2sg312arlbq1lm405nhdo5mg8svb9c4tc1o!nc_n_webp_mw_1']" +64faf4c10000000013029aa8,来我家乡玩一天|株洲(摄影篇),670,"['http://sns-webpic-qc.xhscdn.com/202405262335/e8929a89182a36e2eeb14d08006f1e13/1040g00830ooojr0uja005ntf78ngbvt530c3310!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/4d02c4dcb10d8bfd99fba31f23e5b43d/1040g00830ooojr0uja0g5ntf78ngbvt56uu6hcg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/59c99c4fead9149ed9d0ef3b06f5317a/1040g00830ooojr0uja105ntf78ngbvt5756ingo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/6d471acd59a07edac817f5ee01bdc208/1040g00830ooojr0uja1g5ntf78ngbvt5qfn890g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/232537ce8da808a9bea6f5b98a4eee7c/1040g00830ooojr0uja205ntf78ngbvt55gqfj7o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/83650ea5dfeecc2dc7ce2f2ea583bf2e/1040g00830ooojr0uja2g5ntf78ngbvt5ms9peu8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/b13db1e19a60eb3a7599e12395aa8d7b/1040g00830ooojr0uja305ntf78ngbvt5v5pquco!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/2203f9eadb2a9821a582402b222b2e25/1040g00830ooojr0uja3g5ntf78ngbvt5lpgpou0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/ca64f991606cee6066bc44407e5e6fcc/1040g00830ooojr0uja405ntf78ngbvt55u812m8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/1228c4bbf760f653bfda5917adb091f9/1040g00830ooojr0uja4g5ntf78ngbvt5404akq0!nc_n_webp_mw_1']" +66374d0c000000001e024a2a,第一次去株洲买衣服600拿下16件🧚‍♀️附地图,513,"['http://sns-webpic-qc.xhscdn.com/202405262335/b7564ebb55c666e4e7557301fa6df5a3/1040g2sg312dmcjpum6005nfj92b097favpltcp8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/205758db28533f36a48c47ea7c76fd82/1040g2sg312dmcjpum60g5nfj92b097fa845f1gg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/c57dc6d35b76cce82b208fb4efde1684/1040g2sg312dmcjpum6105nfj92b097fa4unkd70!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/7d5255dfb23ba6ef70e40c97367e01a6/1040g2sg312dmcjpum61g5nfj92b097fa555atug!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/af7a79fba1b14915d2f209730fbc1a1f/1040g2sg312dmcjpum6205nfj92b097faatf8q2o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/7de547491e5e8eb28a6784110d359c85/1040g2sg312dmcjpum62g5nfj92b097fac4prjjg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/1f46f3066cee886d1ba921463d457dd6/1040g2sg312dmcjpum6305nfj92b097fafqm8dug!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/3aea8f5587c49a3b9f6d0c20fbbaee63/1040g2sg312dmcjpum63g5nfj92b097favom8ahg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/7eb4458e4154b10a30cb77257a75a9a5/1040g2sg312dmcjpum6405nfj92b097fabs5q1i0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/5020d42e5ad56ae5fe21aa9879ade1ac/1040g2sg312dmcjpum64g5nfj92b097faa8bh7p0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/37d5ef740c9292113e173b29b08c565f/1040g2sg312dmcjpum6505nfj92b097fagcduia8!nc_n_webp_mw_1']" +647f691f00000000110121e6,株洲小姐们文艺拍照的地方📷,498,"['http://sns-webpic-qc.xhscdn.com/202405262335/609876ecfccc8756f3dd9f85ad117422/1000g0082k0f7rjkj80005nmrc8tg8rthaajfmmo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/df0f93858aac36ad70ee0837cca59227/1000g0082k0f7rjkj800g5nmrc8tg8rthfs04768!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a14e90e055630e3bea2a599b2ee88cfb/1000g0082k0f7rjkj80105nmrc8tg8rtht1p9cd0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/f6ccead0fb17b8575cf90e9689edb139/1000g0082k0f7rjkj801g5nmrc8tg8rthoh4brdg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/238bc5da872c855ccb94f99f4caa4fcf/1000g0082k0f7rjkj80205nmrc8tg8rthrbjpchg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/41d9e10e2dfe1c253038df28db7916a5/1000g0082k0f7rjkj802g5nmrc8tg8rthbln7k18!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/b41f231dde02a999ebeba3ea8ace9132/1000g0082k0f7rjkj80305nmrc8tg8rth2etddso!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/896408cf1c814ee09d52b6f1eaf16916/1000g0082k0f7rjkj803g5nmrc8tg8rthbftroh8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a1336ced38c0ee2a916bd06efc42da17/1000g0082k0f7rjkj80405nmrc8tg8rthij37r6o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/0a371bae50798c5956bf9a77c0668ea8/1000g0082k0f7rjkj804g5nmrc8tg8rthqmu2o7o!nc_n_webp_mw_1']" +653a7af5000000002500a2e2,株洲两天一夜保姆级旅游攻略,请注意查收❗,493,"['http://sns-webpic-qc.xhscdn.com/202405262335/0edaa11e25899daccb1112c9acf17964/1040g00830qmpnb2o10605nvkaa6091r1j197o68!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/423f8b6740d5f4317ba317087a3734e2/1040g00830qmpnb2o10405nvkaa6091r1ic4vhl0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/da1a2d1d4f54743e93c52f6a67235705/1040g00830qmpnb2o103g5nvkaa6091r18ed2vug!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/3e5c8d7b1bfb3f88ad7fd129691308e9/1040g00830qmpnb2o10205nvkaa6091r1v9o9klo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/cb8fcd7ebb06e3d5cbdf0edc20302004/1040g00830qmpnb2o101g5nvkaa6091r1u7e856g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/f16e0b4b650be0631254da04811f38b6/1040g00830qmpnb2o104g5nvkaa6091r18150jfo!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/53e5ba25b9dad5f1368b709d27476038/1040g00830qmpnb2o10505nvkaa6091r1n4upf08!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a1269a90e4f535e88209e215b1f192e1/1040g00830qmpnb2o10305nvkaa6091r1ffueht0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a777fdd61546940b1616440fbe280852/1040g00830qmpnb2o100g5nvkaa6091r1tae63g8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/d0224a443e995fd76030bf6fa09c2fbb/1040g00830qmpnb2o106g5nvkaa6091r19cplhe0!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/c169cb4d892800829b31191043aaadff/1040g00830qmpnb2o10005nvkaa6091r1q8e1g6o!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/d37838d4645564a49f01f066406f11bb/1040g00830qmpnb2o10105nvkaa6091r1r37cuhg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/8abe46ef28a8ba561b3f85dbdd32b702/1040g00830qmpnb2o105g5nvkaa6091r1vjkuvn8!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/cd16ec3a97e2c70be4fe3db62c8be9ce/1040g00830qmpnb2o102g5nvkaa6091r11g87s2g!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/35d3e4f59d259a041a52c5ade6fd061a/1040g2sg30qmpnv66gmkg5nvkaa6091r14k29f68!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/55026cdcf743a2513ab9b1049a14c297/1040g2sg30qmpnv66gmk05nvkaa6091r13im21fg!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/a41fd5d54331928579b041a7b603feb1/1040g2sg30qmpnv66gmjg5nvkaa6091r1pod4628!nc_n_webp_mw_1', 'http://sns-webpic-qc.xhscdn.com/202405262335/8c6691637fe8edea15aa279c5825691f/1040g2sg30qmpnv66gmig5nvkaa6091r1ubm4q7g!nc_n_webp_mw_1']" diff --git a/pythonProject1/TrialRecommend/func_collec.py b/pythonProject1/TrialRecommend/func_collec.py new file mode 100644 index 0000000..d22f3e1 --- /dev/null +++ b/pythonProject1/TrialRecommend/func_collec.py @@ -0,0 +1,36 @@ +import csv +import mysql.connector +from tkinter import messagebox + +def collec(user,data_index): + id='' + with open('data.csv', 'r',encoding='utf-8', newline='') as file: + reader = csv.reader(file) + index=0 + for row in reader: + if index == data_index: + id=row[0] + index=index+1 + db = mysql.connector.connect( + host="localhost", + user="root", + passwd="A121023020309a", + database="trial" + ) + + sql='INSERT INTO trial.collections (user_id, essay_id) VALUES (%s, %s)' + cursor=db.cursor() + success='true' + try: + cursor.execute(sql, (user, id)) + db.commit() + except db.Error as e: + print(f"An error occurred: {e}") + db.rollback() + messagebox.showinfo("Error", "收藏失败!") + success='false' + finally: + # 确保cursor关闭,释放资源 + cursor.close() + if success == 'true': + messagebox.showinfo('提示','收藏成功!') \ No newline at end of file diff --git a/pythonProject1/TrialRecommend/notes.csv b/pythonProject1/TrialRecommend/notes.csv new file mode 100644 index 0000000..2c5257e --- /dev/null +++ b/pythonProject1/TrialRecommend/notes.csv @@ -0,0 +1,2 @@ +第一次去株洲买衣服 500元买了9件 ,📍进货地点:新天地、巨丰、意法三个商场
🛒进货战况:534元买了1双鞋、1条裤子、2条连衣裙、5件上衣,共计9件,平均不到60元!!!

1️⃣第一站:新天地 ⭐⭐⭐⭐
预算有限的学生党首选商场,价格意外美丽(基本不让砍价,最多砍个2-5元),T恤很多都是50元3件,连衣裙很少过百,反正就穿1个夏天,还在乎什么~~因为不让试穿,我都尽量选不带大印花、大logo等相对日常不会出错的基本款
新天地分为两层,负一层营业时间:早7:00-16:00,负二层营业时间:早4:00-12:00,大家要注意营业时间哦,去晚了很多店都关门了(主打一个佛系)

2️⃣第二站:巨丰 ⭐️⭐️⭐️⭐️⭐️
感觉巨丰的款式和质量比新天地好太多,价格没有那么白菜,但也很平价了!很适合年轻姐妹细逛,韩系/辣妹/Y2k等等风格都有,但也是不让试穿和不砍价(遇到好点的老板还是会象征性少一点),实在把握不准上身效果可以问老板看她手机里有模特图吗
价位:上衣50-70元不等,连衣服/套装裙:109-129元不等,裤子:70-89元不等

3️⃣第三站:意法 ⭐⭐⭐⭐
最大的优点就是可以试穿!年轻姐妹可以主逛负1楼-2楼,负1楼是包包、鞋子、饰品,1-2楼年轻女装,价格相对便宜,淘到一条质量超级棒的黑色长裙只要120元,也能砍价,时间够还是值得细逛的(5点就关门哦)
逛完这3个商场,我和姐妹累成废柴,但看到收获的美丽衣服,可快乐了!

,2023-06-25 ,4191,5972,3396 +株洲敲适合city walk的一条街🍂好逛又好拍 ,就在市中心!!
王府井对面,株百后面的巷子里
好多人不知道
定位📍文艺巷
这一条街全是好看又治愈的宝藏小店
,2023-10-04 ,2832,5933,3400 diff --git a/pythonProject1/URL.txt b/pythonProject1/URL.txt new file mode 100644 index 0000000..ca1a02a --- /dev/null +++ b/pythonProject1/URL.txt @@ -0,0 +1,5 @@ +阿里云 http://mirrors.aliyun.com/pypi/simple/ +中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ +豆瓣 http://pypi.douban.com/simple/ +清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ +中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/ \ No newline at end of file