简单爬虫,蜘蛛

伱注定s我的 2013-10-25 11:52:37
下面写了一个简单读取的案例,请问要怎样来获取页面动态加载的信息.

package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Test1 {
public static void main(String[] args) throws IOException {

URL urlmy = new URL("http://hotel.qunar.com/city/guangzhou/dt-5725/?tag=guangzhou#fromDate=2013-11-09&toDate=2013-11-10&q=%E5%B9%BF%E5%B7%9E%E7%B2%A4%E6%B5%B7%E5%96%9C%E6%9D%A5%E7%99%BB%E9%85%92%E5%BA%97&from=qunarindex%7Csug&filterid=e711d861-9aa5-449f-9089-8ac9ad8a0174_C&showMap=0&qptype=hotelName|poi&haspoi=1&from=qunarindex%7Csug&QHFP=ZSS_A3A44DB2&QHPR=1_1_0_0");
HttpURLConnection con = (HttpURLConnection) urlmy.openConnection();
con.setFollowRedirects(true);
con.setInstanceFollowRedirects(false);
con.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
String str = "";
StringBuffer reader = new StringBuffer("");
while ((str = br.readLine()) != null) {
reader.append(str+"\r\n");
}
System.out.println(reader);
}
}


...全文
235 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
伱注定s我的 2013-10-25
  • 打赏
  • 举报
回复

如果我想获取去哪儿上面的价格信息.
但是它们是动态的信息,也就是页面加载之后.
1.加载页面后第一次加载,可能是js控制.
2.按 重新搜索 获取价格信息.

<table cellspacing="0" cellpadding="0">
<tr>
<th>入住日期</th>
<td valign="top" class="c1">
<div class="qcbox qdate fromD">
<input class="textbox" id="refromDate" name="refromDate" maxlength="10" autocomplete="off"/>
</div>
</td>
<th>离店日期</th>
<td valign="top" class="c2">
<div class="qcbox qdate toD">
<input class="textbox" id="retoDate" name="retoDate" maxlength="10" autocomplete="off"/>
</div>
</td>
<td valign="top" class="c3"><button class="btn_research" onclick="bookTool.research('')"><b>重新搜索</b></button></td>
</tr>
<tr>
<td colspan="5">
<div class="searchresulttips">
<div class="proc" id="statusBar"></div>
<div class="proc_none" id="nonePrice">正在获取该酒店信息...</div>
<div class="scheduled" id="lastBooking"></div>
</div>
</td>
</tr>
</table>
失落夏天 2013-10-25
  • 打赏
  • 举报
回复
引用 楼主 sq308587563 的回复:
下面写了一个简单读取的案例,请问要怎样来获取页面动态加载的信息.

package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Test1 {
	public static void main(String[] args) throws IOException {

		URL urlmy = new URL("http://hotel.qunar.com/city/guangzhou/dt-5725/?tag=guangzhou#fromDate=2013-11-09&toDate=2013-11-10&q=%E5%B9%BF%E5%B7%9E%E7%B2%A4%E6%B5%B7%E5%96%9C%E6%9D%A5%E7%99%BB%E9%85%92%E5%BA%97&from=qunarindex%7Csug&filterid=e711d861-9aa5-449f-9089-8ac9ad8a0174_C&showMap=0&qptype=hotelName|poi&haspoi=1&from=qunarindex%7Csug&QHFP=ZSS_A3A44DB2&QHPR=1_1_0_0");
		HttpURLConnection con = (HttpURLConnection) urlmy.openConnection();
		con.setFollowRedirects(true);
		con.setInstanceFollowRedirects(false);
		con.connect();
		BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
		String str = "";
		StringBuffer reader = new StringBuffer("");
		while ((str = br.readLine()) != null) {
			reader.append(str+"\r\n");
		}
		System.out.println(reader);
	}
}
你这动态加载大体上是什么意思呢?我感觉你说的和我们常用的那个动态加载概念上好像有一点区别。 另外,你准备爬的是什么信息呢? 应该不会是简单的网页吧。
teemai 2013-10-25
  • 打赏
  • 举报
回复
分析下动态请求url,继续往下面请求。
伱注定s我的 2013-10-25
  • 打赏
  • 举报
回复
SADSDSDDASDASD 2013-10-25
  • 打赏
  • 举报
回复
这个只能帮你顶一下 这个真心不懂得
伱注定s我的 2013-10-25
  • 打赏
  • 举报
回复
引用 5 楼 rui888 的回复:
上次论坛里也有人爬 去哪 的数据 。
有原帖吗?发出来看看咯~!
tony4geek 2013-10-25
  • 打赏
  • 举报
回复
上次论坛里也有人爬 去哪 的数据 。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧