Open SlothSimon opened 7 years ago
因为在房价网站上爬取到的数据只有基本的房屋信息,所以,需要通过百度API二次爬取周边信息,你可以点击数据抓取,先对房屋的坐标信息进行抓取,然后再爬周边信息,医院地铁什么的
在db/seed.rb文件中:
# file = File.read('db/housedata.json')
#
# file.gsub(/\{(.*?)\}/).each do |line|
# hash=JSON.parse(line)
# house=House.new
# house.area=hash['area'][0].scan(/[0-9]/).join.to_i
# house.url=hash['url'][0]
# house.average_price=hash['average_price'][0].scan(/[0-9]/).join.to_i
# house.floor=hash['floor'][0]
# house.build_time=hash['build_time'][0].scan(/[0-9]/).join
# house.community=hash['location'][0].delete(' ').scan(/\n(.*?)\n/).join.gsub("\u00A0","")
# house.street=hash['location'][0].delete(' ').scan(/\[(.*?)\]/).join
# house.room_shape=hash['room_shape'][0]
# house.save
# end
User.create(
name: "彭兆卿",
email: "admin@housepricing.com",
password: "password",
password_confirmation: "password",
admin: true
)
把注释取消,然后保存,在终端中运行rake db:seed,把基础数据写进数据库里,用管理员用户密码登录后就可以与Baidu API交互抓取了
如果你不想抓取,在根目录下我有数据库备份,mydb.dump,导入即可
你在抓取的过程中或者导入过程中,可能会报错,因为我的数据表有些字段已经改了,现在在弄新版本,抱歉,如果你真的想用,我过两天把数据表格式改回来
回复的好快好及时! 我用你提供的工具抓了别的城市的数据放了进去,目前尝试中。 万分感谢! P.S. 这个工具的可视化做的好棒!
有什么问题尽管问我
PS:如果一直没人问津,我都快写不下去啦哈哈
我把本地的数据表格改啦~都加了distance列,感觉要抓好一会。在观察抓取周边设施结果时,经常会出现error 2,不知道这种是什么情况?
有两种可能,第一种是与百度API交互错误,可以通过F12中的控制台查看
也有可能是拿到数据后提交到本地服务器失败,可以在rails的log里查看到
是在控制台出现的,重试post还是会error 2,是不是附近没有相关设施(比如写字楼)就有可能报这个错?
你把错误截个图我看看,控制台的
那个Error in location xxx, xxx 是我自己加的调试信息
你看看rails的log,有问题吗,截一段来看看
rails的log在给表格加上distance字段后就没有报过错了。
对了,差点忘了说,我把works_controller.rb里面10-16行注释了。
搜了一下getStatus的结果,数字2貌似是代表“BMAP_STATUS_UNKNOWN_LOCATION 位置结果未知”,不知道这算不算是没找到相关基础设施……
嗯好,我来看看
@SlothSimon 我刚刚把最新的上传了, 主要修改:把distance属性放到了buses_houses关联表里,修改了一些buses_controller
经过我本地测试,可以使用,如果你觉得没问题,我就把剩下的医院、地铁其他的都一并修改了,现在只看公交车周边能不能抓取
(゚∀゚ )使用了一下棒棒哒!避免重复抓取功能好极了!
Tips: 抓取的过程中,你可以打开多个浏览器同时进行,并行抓取 : )
感觉数据库和网页抓取时用的数据不一致。
因为有些小区的经纬度错了,我就在数据库中直接改成正确的,然后再去抓取公交车站,但是发现在浏览器控制台里打印出来的依然是错误的经纬度。
删除了tmp文件夹重新运行rails s也没有用。
是的,我抓取的过程中,首先使用房屋的地址定位,若地址为空,再通过小区名定位,没有直接使用数据库中的经纬度,一会就改过来
ok,已经改好了直接读取数据库中的经纬度抓取
打开数据列表会在页面上报错,主要报错信息如下:
查看了一下自己导入的数据库发现Houses表中没有医院、学校等字段,不知是不是数据库还要做进一步的处理?
感谢!