php抓取动态页面内容,httpclient怎么完整抓取php动态加载网页

httpclient如何完整抓取php动态加载网页

本人准备用海词的Web API接口http://dict.cn/mini.php?q=word 写一个本地客服端查词程序

用httpclient3.1访问后得到的是:

Define book : [buk]

正在加载的翻译解释

例句与用法:

正在加载的相关例句与用法

词形变化:

正在加载的词形变化

加入生词本  看详细解释

而我想得到的是从浏览器直接打开的效果 :

Define book : [buk]

n.书, 本子

v.预订, 记录在案

例句与用法:

1. He was booked by the referee for foul play.

他因为动作犯规而被裁判记下姓名。

2. He's always careful to do things by the book.

他总是小心翼翼地按规章办事。

3. You'll have to book early if you want to see that fashion show.

你要想看那场时装表演的话,就得早点儿定座位。

4. He was booked on a charge of speeding.

他因超速开车而被记录在案。

词形变化:

名词:booker  动词过去式:booked  动词过去分词:booked  动词现在分词:booking  动词第三人称单数:books

加入生词本  看详细解释

请问在j2se中如何实现?

附代码:

import java.io.*;

import org.apache.commons.httpclient.methods.*;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.params.HttpMethodParams;

class HC_t{

public static void main(String[] args) {

System.out.println("qgb");

HttpClient httpClient = new HttpClient();

GetMethod getMethod = new GetMethod("http://dict.cn/mini.php?q=book");

getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,

new DefaultHttpMethodRetryHandler());

try {

int statusCode = httpClient.executeMethod(getMethod);

if (statusCode != HttpStatus.SC_OK) {

System.err.println("Method failed: " + getMethod.getStatusLine());

}

byte[] responseBody = getMethod.getResponseBody();

FileOutputStream fos=new FileOutputStream("1.htm");

fos.write(responseBody);

//System.out.println(new String(responseBody));

}

catch (HttpException e) {

System.out.println("Please check your provided http address!");

e.printStackTrace();

}

catch (IOException e) {

e.printStackTrace();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值