java爬周边信息解决方案

日前用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值