安居客二手房

2021/1/14 下午1:26:45

  1. // ==UserScript==
  2. // @name 安居客二手房
  3. // @namespace Violentmonkey Scripts
  4. // @match https://wuhan.anjuke.com/sale/*
  5. // @grant none
  6. // @version 1.0
  7. // @author -
  8. // @description 2021/1/14 下午1:26:45
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. var list = $('.sale-left ul#houselist-mod-new li');
  13. var arrayJson = new Array()
  14. $.each( list, function( key, val ) {
  15. var info = $(val).children('div.house-details')[0];
  16. var priceInfo = $(val).children('div.pro-price')[0];
  17. var url = $(info).children('div.house-title').children('a').attr('href');
  18. var title = $(info).children('div.house-title').children('a').attr('title');
  19. var positions = $(info).children('div.details-item:eq(1)').children('span').attr('title').split(/\s+/);
  20. var houseinfos = $(info).children('div.details-item:eq(0)').text().split('|');
  21. var tags = $(info).children('div.tags-bottom').children('span').text();
  22. var price = $(priceInfo).children('span:first').text();
  23. var unitprice = $(priceInfo).children('span:last').text();
  24. price = priceConvert(price);
  25. unitprice = unitprice.replace('元/m²','');
  26. var data = {
  27. url :url,
  28. title:title,
  29. lpName:strTrim(positions[0]),
  30. pos:strTrim(positions[1].split('-')[0]),
  31. tag:tags,
  32. totalprice:price,
  33. unitprice:unitprice,
  34. pushDate:-1,
  35. follow:0
  36. }
  37. houseinfoeach(data,houseinfos)
  38. arrayJson.push(data);
  39. });
  40. save(arrayJson ,'result.json');
  41. // 等待3 秒
  42. setTimeout(
  43. function()
  44. {
  45. if($('.multi-page a:last').hasClass('aNxt')){
  46. // 下一页
  47. window.location.href = $('.multi-page a.aNxt:last').attr('href');
  48. }
  49. }, 3000);
  50. })();
  51.  
  52. function priceConvert(price){
  53. var i = price.indexOf('万');
  54. if(i >= 0){
  55. var temp = price.substr(0,i) * 10000
  56. return temp;
  57. }
  58. return price;
  59. }
  60.  
  61. // 保存为json文件
  62. function save(data, filename){
  63. if(!data) {
  64. console.error('Console.save: No data')
  65. return;
  66. }
  67. if(!filename) filename = 'console.json'
  68. if(typeof data === "object"){
  69. data = JSON.stringify(data, undefined, 4)
  70. }
  71. var blob = new Blob([data], {type: 'text/json'}),
  72. e = document.createEvent('MouseEvents'),
  73. a = document.createElement('a')
  74. a.download = filename
  75. a.href = window.URL.createObjectURL(blob)
  76. a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
  77. e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
  78. a.dispatchEvent(e)
  79. }
  80.  
  81. function houseinfoeach(data,houseinfos){
  82. var result = "";
  83. try{
  84. if(houseinfos.length <= 4){
  85. if(strTrim(houseinfos[0]).indexOf('室')){
  86. data.shi = strTrim(houseinfos[0]).split('室')[0];
  87. if (strTrim(houseinfos[0]).split('室')[1].indexOf('厅')){
  88. data.ting = strTrim(houseinfos[0]).split('室')[1].replace('厅','');
  89. }else{
  90. data.ting = 0;
  91. }
  92. }else{
  93. data.shi = 0;
  94. data.ting = 0;
  95. }
  96. data.mianji = strTrim(houseinfos[1]).replace('m²','');
  97. data.chaoxiang = '';
  98. data.zhuangxiu = '';
  99. data.louceng = strTrim(houseinfos[2]);
  100. data.date = strTrim(houseinfos[3]);
  101. data.louxing = '';
  102. }
  103.  
  104. if(houseinfos.length > 4){
  105. var temp = "";
  106. for (var i = 4 ; i < houseinfos.length(); i ++ ){
  107. temp += houseinfos[i]
  108. }
  109. data.otherInfo = temp;
  110. }
  111. }catch(e){
  112. console.log(e)
  113. }
  114. }
  115.  
  116. function strTrim(str){
  117. var result = "";
  118. try{
  119. if(str){
  120. result = str.trim();
  121. }else{
  122. result = "无";
  123. }
  124. }catch(e){
  125. result = str;
  126. }
  127. return result;
  128. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址