|
|
@ -13,12 +13,8 @@ class Home():
|
|
|
|
self.root = tk.Tk()
|
|
|
|
self.root = tk.Tk()
|
|
|
|
self.root.title("购房推荐系统")
|
|
|
|
self.root.title("购房推荐系统")
|
|
|
|
self.root.geometry("650x350+500+200")
|
|
|
|
self.root.geometry("650x350+500+200")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.Max_index = ''
|
|
|
|
self.Max_index = ''
|
|
|
|
self.Current_index = 1
|
|
|
|
self.Current_index = 1
|
|
|
|
# 把爬取的三条信息组成一个元组捆绑,变成一条记录
|
|
|
|
|
|
|
|
self.all_info = []
|
|
|
|
self.all_info = []
|
|
|
|
self.text=''
|
|
|
|
self.text=''
|
|
|
|
|
|
|
|
|
|
|
@ -38,7 +34,7 @@ class Home():
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_line=tk.Button(self.root,text="同比房价",command=self.open_line)
|
|
|
|
self.btn_line=tk.Button(self.root,text="同比房价",command=self.open_line)
|
|
|
|
self.btn_line.place(relx=0.2, rely=0.8, relheight=0.10, relwidth=0.13)
|
|
|
|
self.btn_line.place(relx=0.2, rely=0.8, relheight=0.10, relwidth=0.13)
|
|
|
|
|
|
|
|
# 启动窗口事件
|
|
|
|
self.root.mainloop()
|
|
|
|
self.root.mainloop()
|
|
|
|
def open_map(self):
|
|
|
|
def open_map(self):
|
|
|
|
map()
|
|
|
|
map()
|
|
|
@ -60,6 +56,7 @@ class Home():
|
|
|
|
addresses = e.xpath('//div[@class="address"]/a/@title')
|
|
|
|
addresses = e.xpath('//div[@class="address"]/a/@title')
|
|
|
|
prices = [d.xpath('string(.)').strip() for d in e.xpath('//div[@class="nhouse_price"]')]
|
|
|
|
prices = [d.xpath('string(.)').strip() for d in e.xpath('//div[@class="nhouse_price"]')]
|
|
|
|
if index=='1' and self.Max_index=='':
|
|
|
|
if index=='1' and self.Max_index=='':
|
|
|
|
|
|
|
|
# 从网页获取最大页数
|
|
|
|
lasts = e.xpath('//a[@class="last"]/@href')
|
|
|
|
lasts = e.xpath('//a[@class="last"]/@href')
|
|
|
|
if len(lasts)!=0:
|
|
|
|
if len(lasts)!=0:
|
|
|
|
the_string = lasts[-1]
|
|
|
|
the_string = lasts[-1]
|
|
|
@ -69,17 +66,19 @@ class Home():
|
|
|
|
return 'False'
|
|
|
|
return 'False'
|
|
|
|
|
|
|
|
|
|
|
|
for name, address, price in zip(names, addresses, prices):
|
|
|
|
for name, address, price in zip(names, addresses, prices):
|
|
|
|
|
|
|
|
# 将数据添加到列表中
|
|
|
|
self.all_info.append((name, price, address))
|
|
|
|
self.all_info.append((name, price, address))
|
|
|
|
return self.all_info
|
|
|
|
return self.all_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 展示图表数据函数
|
|
|
|
# 展示图表数据函数
|
|
|
|
def show_data_in_table(self,data):
|
|
|
|
def show_data_in_table(self,data):
|
|
|
|
|
|
|
|
# 创建一个子窗口
|
|
|
|
self.popup = tk.Toplevel(self.root)
|
|
|
|
self.popup = tk.Toplevel(self.root)
|
|
|
|
self.popup.geometry('500x500')
|
|
|
|
self.popup.geometry('500x500')
|
|
|
|
self.popup.title("购房信息详情")
|
|
|
|
self.popup.title("购房信息详情")
|
|
|
|
|
|
|
|
|
|
|
|
# 使用pandas DataFrame处理数据
|
|
|
|
# 使用pandas DataFrame处理数据,二维表格数据结构
|
|
|
|
df = pd.DataFrame(data, columns=["楼盘名称", "价格", "地区"])
|
|
|
|
df = pd.DataFrame(data, columns=["楼盘名称", "价格", "地区"])
|
|
|
|
# 创建Treeview部件,显式指定列ID
|
|
|
|
# 创建Treeview部件,显式指定列ID
|
|
|
|
tree = ttk.Treeview(self.popup, columns=("name", "price", "area"), show="headings")
|
|
|
|
tree = ttk.Treeview(self.popup, columns=("name", "price", "area"), show="headings")
|
|
|
@ -100,7 +99,6 @@ class Home():
|
|
|
|
vsb = ttk.Scrollbar(self.popup, orient="vertical", command=tree.yview)
|
|
|
|
vsb = ttk.Scrollbar(self.popup, orient="vertical", command=tree.yview)
|
|
|
|
tree.configure(yscrollcommand=vsb.set)
|
|
|
|
tree.configure(yscrollcommand=vsb.set)
|
|
|
|
vsb.pack(side='right', fill='y')
|
|
|
|
vsb.pack(side='right', fill='y')
|
|
|
|
|
|
|
|
|
|
|
|
tree.pack(fill='both', expand=True)
|
|
|
|
tree.pack(fill='both', expand=True)
|
|
|
|
|
|
|
|
|
|
|
|
# 添加底部框架用于放置翻页按钮
|
|
|
|
# 添加底部框架用于放置翻页按钮
|
|
|
@ -149,6 +147,7 @@ class Home():
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
messagebox.showinfo(message='末尾')
|
|
|
|
messagebox.showinfo(message='末尾')
|
|
|
|
|
|
|
|
|
|
|
|
# 首页点击函数
|
|
|
|
# 首页点击函数
|
|
|
|
def on_button_click(self,text, index='1'):
|
|
|
|
def on_button_click(self,text, index='1'):
|
|
|
|
self.Max_index = ''
|
|
|
|
self.Max_index = ''
|
|
|
@ -170,12 +169,12 @@ class Home():
|
|
|
|
"石景山": "shijingshan",
|
|
|
|
"石景山": "shijingshan",
|
|
|
|
"密云": "miyun",
|
|
|
|
"密云": "miyun",
|
|
|
|
}.get(text, "未知区域")
|
|
|
|
}.get(text, "未知区域")
|
|
|
|
|
|
|
|
|
|
|
|
self.text=text
|
|
|
|
self.text=text
|
|
|
|
# 把选择的区域 传入通过fetch传入url
|
|
|
|
|
|
|
|
if self.fetch_data(simplified_text, index)!="False":
|
|
|
|
if self.fetch_data(simplified_text, index)!="False":
|
|
|
|
|
|
|
|
# 把选择的区域 传入通过fetch传入url
|
|
|
|
data = self.fetch_data(simplified_text, index)
|
|
|
|
data = self.fetch_data(simplified_text, index)
|
|
|
|
# 网页地址传给展示页面
|
|
|
|
# 获取的数据传给表格
|
|
|
|
self.show_data_in_table(data)
|
|
|
|
self.show_data_in_table(data)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
messagebox.showinfo(message='该地区暂无数据!')
|
|
|
|
messagebox.showinfo(message='该地区暂无数据!')
|
|
|
@ -184,7 +183,6 @@ class Home():
|
|
|
|
# 获取屏幕宽度和高度
|
|
|
|
# 获取屏幕宽度和高度
|
|
|
|
screen_width = self.popup.winfo_screenwidth()
|
|
|
|
screen_width = self.popup.winfo_screenwidth()
|
|
|
|
screen_height = self.popup.winfo_screenheight()
|
|
|
|
screen_height = self.popup.winfo_screenheight()
|
|
|
|
|
|
|
|
|
|
|
|
# 计算窗口的左上角应该放置的位置
|
|
|
|
# 计算窗口的左上角应该放置的位置
|
|
|
|
left = (screen_width / 2) - (width / 2)
|
|
|
|
left = (screen_width / 2) - (width / 2)
|
|
|
|
top = (screen_height / 2) - (height / 2)
|
|
|
|
top = (screen_height / 2) - (height / 2)
|
|
|
|