123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- # -*- 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():
- # # 价格列表
- # price_list = []
- # periphery_name_list = get_periphery()[0]
- # periphery_url_list = get_periphery()[1]
- #
- # # 主函数
- # for i in range(len(periphery_name_list)):
- # name = periphery_name_list[i]
- # url = periphery_url_list[i]
- url = 'https://www.anjuke.com/fangjia/hf2024/bhgyy/'
- 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
- list = []
- 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)
- zhongji.append(a)
- UporDown = table_tr.find('div',class_ = "up") or table_tr.find('div',class_ = "down")
- if UporDown.find('div',class_ = "up"):
- tab = '↑'
- else:
- if UporDown.find('div', class_="down"):
- tab = '↓'
- else:
- tab = '未找到趋势'
- zhongji.insert(2,tab)
- list.append(zhongji)
- print('zhongji',zhongji)
- print('list',list)
- # print(list[0][2])
- # return list
- if __name__ == '__main__':
- print(get_price())
|