get_price.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. # @Author : ChenZhaoyuchen
  3. # @Time : 2024/9/27 16:17
  4. # @File : get_price.py
  5. import requests
  6. from anjuke.utils.get_message import *
  7. from anjuke.utils.setting import *
  8. def get_price():
  9. # # 价格列表
  10. # price_list = []
  11. # periphery_name_list = get_periphery()[0]
  12. # periphery_url_list = get_periphery()[1]
  13. #
  14. # # 主函数
  15. # for i in range(len(periphery_name_list)):
  16. # name = periphery_name_list[i]
  17. # url = periphery_url_list[i]
  18. url = 'https://www.anjuke.com/fangjia/hf2024/bhgyy/'
  19. response_price = requests.get(url = url, headers = headers).content.decode('utf8')
  20. soup = BeautifulSoup(response_price, 'html.parser')
  21. price_ = soup.find(class_ = "table is-headless")
  22. table_trs = price_.find_all('div',class_ = "table-tr")
  23. # html提取 时间time,单价price,涨跌tab,涨跌比率Price_Rate
  24. list = []
  25. for table_tr in table_trs:
  26. all_mes = table_tr.find_all('div',class_ = 'td')
  27. zhongji = []
  28. for td in all_mes:
  29. a = td.text.strip() # 防止出现换行符等符号错误
  30. print('a',a)
  31. zhongji.append(a)
  32. UporDown = table_tr.find('div',class_ = "up") or table_tr.find('div',class_ = "down")
  33. if UporDown.find('div',class_ = "up"):
  34. tab = '↑'
  35. else:
  36. if UporDown.find('div', class_="down"):
  37. tab = '↓'
  38. else:
  39. tab = '未找到趋势'
  40. zhongji.insert(2,tab)
  41. list.append(zhongji)
  42. print('zhongji',zhongji)
  43. print('list',list)
  44. # print(list[0][2])
  45. # return list
  46. if __name__ == '__main__':
  47. print(get_price())