# -*- coding: utf-8 -*- # @Author : ChenZhaoyuchen # @Time : 2024/9/27 16:17 # @File : get_price.py import requests from anjuke.utils.get_message import * from anjuke.utils.setting import * def get_price(): # 价格列表 periphery_name_list = get_periphery()[0] periphery_url_list = get_periphery()[1] # 主函数 result = [] for i in range(len(periphery_name_list)): name = periphery_name_list[i] url = periphery_url_list[i] # url = 'https://www.anjuke.com/fangjia/beijing2024/chaoyang/' response_price = requests.get(url = url, headers = headers).content.decode('utf8') soup = BeautifulSoup(response_price, 'html.parser') price_ = soup.find(class_ = "table is-headless") table_trs = price_.find_all('div',class_ = "table-tr") # html提取 时间time,单价price,涨跌tab,涨跌比率Price_Rate list1 = [] for table_tr in table_trs: all_mes = table_tr.find_all('div',class_ = 'td') zhongji = [] for td in all_mes: a = td.text.strip() # 防止出现换行符等符号错误 print('a',a) # 每轮3个a值,包括时间time,单价price,涨跌比率Price_Rate zhongji.append(a) UporDown = table_tr.find( 'div', class_="up") or table_tr.find('div', class_="down") attr = UporDown['class'][0] if attr == "up": tab = 'UP' elif attr == "down": tab = 'DOWN' else: tab = 'CONSTANT' zhongji.insert(2,tab) list1.append(zhongji) list1.append(name) result.append(list1) return result # if __name__ == '__main__': # connectMysql() # get_price() # closeMysql(conn = )