java京东查询物流轨迹事例_Java爬虫实现京东物流查询

本文展示了如何利用Java编写代码查询京东物流轨迹。通过设置请求头和解析HTML内容,获取包裹的最新状态信息,包括签收情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网上没有免费的接口,只能自己写一套了,参考代码如下

public static JSONObject getLastInfo(String no){

JSONObject jsonObject=new JSONObject();

jsonObject.put("no", no);

Connection connection=Jsoup.connect("http://www.jdwl.com/order/search?waybillCodes="+no);

connection.header("Referer", "");

connection.header("Host", "www.jdwl.com");

connection.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");

connection.header("Accept-Language", "zh-CN,zh;q=0.9");

connection.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36");

Document document;

try {

document = connection.timeout(3000).get();

Element element=document.select(".b-new-search-list").first();

if(element!=null){

jsonObject.put("accept_time",element.select(".time").first().text()+" "+element.select(".b-new-search-time").first().text() );

String remark=element.select(".b-new-search-info").first().text();

jsonObject.put("remark",remark);

if(remark!=null&&(remark.indexOf("签收")>-1||remark.indexOf("期待再次为您服务")>-1)){

jsonObject.put("opcode",80);

}else{

jsonObject.put("opcode",30);

}

GpicLogger.getExpress().info(jsonObject);

return jsonObject;

}

return null;

} catch (IOException e) {

GpicLogger.getExpress().error(no+">>>"+e);

return null;

}

}

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

System.out.println(getLastInfo("JDVE00197954011"));

}

原文:https://www.cnblogs.com/java-rocky/p/11763864.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值