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