java爬取链家网数据

	int num = 1;
		String path = "D:\\房源信息.txt";
		BufferedWriter bf = new BufferedWriter(new FileWriter(path));
		while(num<=100){
			String link = "https://bj.lianjia.com/ershoufang/pg"+num;
			Document document = Jsoup.connect(link).get();
			Elements byClass = document.getElementsByClass("sellListContent");
			Elements li = byClass.select("li");
			for(int i = 0;i<li.size();i++){
				String attr = li.get(i).select("a").attr("href");
				String attrContent = "房源详情:"+attr;
				bf.write(attrContent);
				bf.newLine();
				
				Element info = li.select("div.info.clear").get(i);
				String title = info.select("div.title").text();
				String titleContent = "房源标题:"+title;
				bf.write(titleContent);
				bf.newLine();
				String addr = info.select("div.address").text();
				String addrContent = "房源地址:"+addr;
				bf.write(addrContent);
				bf.newLine();
				String louceng = info.select("div.flood").text();
				String loucengContent = "房源楼层:"+louceng;
				bf.write(loucengContent);
				bf.newLine();
				String parse = info.select("div.followInfo").text();
				String [] content ;
				String pail = " ";
				content = parse.split(pail);
				for (String por : content) {
					String qiContent = "其他信息:"+por;
					bf.write(qiContent);
					bf.newLine();
				}
				bf.newLine();
				
			}
			num +=1;
		}
		bf.close();
		
		

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值