日前用java爬虫去爬取某些地理信息周边信息的时候,发现大部分网站的周边信息都是预加载页面,用js去调API来实现,不同网站的具体实现方式还不同。所以我这边的解决方案为,先根据所搜目标的名称以及所在区域去调用百度API,获取经纬度,再根据经纬度去搜索周边信息,具体查看百度地图提供的公有API http://lbsyun.baidu.com/index.php?title=webapi
package com.jrzh.thread;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.alibaba.fastjson.JSONObject;
import com.jrzh.bean.jwd.JwdBean;
import com.jrzh.bean.jwd.JwdInfo;
import com.jrzh.common.exception.ProjectException;
import com.jrzh.framework.bean.SessionUser;
import com.jrzh.mvc.model.reptile.ReptileNewHouseModel;
import com.jrzh.mvc.service.reptile.manager.ReptileServiceManage;
import com.jrzh.tools.MyPayUtils;
public class LatitudeLongitudeThread extends Thread {
static Log log = LogFactory.getLog(LatitudeLongitudeThread.class);
private ReptileServiceManage reptileServiceManage;
public LatitudeLongitudeThread(ReptileServiceManage reptileServiceManage) {
this.reptileServiceManage = reptileServiceManage;
}
@Override
public void run() {
// 更新坐标方法
Object object = new Object();
synchronized (object) {
List<ReptileNewHouseModel> reptileNewHouseModelList;
try {
// 查找所有带名称的实例
reptileNewHouseModelList = reptileServiceManage.reptileNewHouseService.findAll();
for (ReptileNewHouseModel reptileNewHouseModel : reptileNewHouseModelList) {
if (reptileNewHouseModel.getLatitude() != null && reptileNewHouseModel.getLongitude() != null) {
// 如果已经有经纬度,直接跳过
continue;
}
try {
// 具体获取坐标方法
String lat = null;
String lng = null;
List<JwdInfo> list = getJwd(reptileNewHouseModel.getHouseCity(),
reptileNewHouseModel.getHouseName());
if (list == null) {
if(reptileNewHouseModel.getHouseOtherName()==null) continue;
list = getJwd(reptileNewHouseModel.getHouseCity(),reptileNewHouseModel.getHouseOtherName());
if(list==null) continue;
}
String[] strs = getJwd(list, reptileNewHouseModel.getHousePart(),
reptileNewHouseModel.getHouseName());
lat = strs[0];
lng = strs[1];
log.info(lat + "----" + lng);
if (lat != null && lng != null) {
reptileNewHouseModel.setLatitude(new BigDecimal(lat));
rept

最低0.47元/天 解锁文章
1539

被折叠的 条评论
为什么被折叠?



