如何通过Java技术从吉时开奖网抓取中奖信息数据?
- 内容介绍
- 文章标签
- 相关推荐
本文共计396个文字,预计阅读时间需要2分钟。
今天有人要爬取这个网站的资料,网址为:https://ig185.com/mkjw//PCEGG_180/index.。我分析了这个网站的代码,发现它是用structs编写的。然后我分析了网络连接,可以直接调用。
今天有个人要爬取这个网站的数据,地址为:
ig185.com/mkjw/html/PCEGG_180/index.html然后我分析了这个网站的代码,发现这个网站是用structs来写的,然后分析网络连接发现,可以直接调用url:
就可以获取到该网页的数据了,由于数据已经是json的数据,我们用fastjson封装编程类数据,我创建的是maven项目,依赖为:
<!-- mvnrepository.com/artifact/org.apache.ig185.com/kaijiangweb/getHistoryList.do?date=&lotCode=PCEGG_180";String html=pickData(url);
System.out.println(html);
Result result = JSON.parseObject(html, new TypeReference<Result>() {});
System.out.println(result.getMessage());
System.out.println(result.getResult());
List<Lottery> lotteries=result.getResult();
for(Lottery lottery:lotteries){
System.out.println(lottery.toString());
System.out.println(lottery.getPreDrawTime());
}
}
/*
* 爬取网页信息
*/
private static String pickData(String url) {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = httpclient.execute(httpget);
try {
// 获取响应实体
HttpEntity entity = response.getEntity();
// 打印响应状态
if (entity != null) {
return EntityUtils.toString(entity);
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
本文共计396个文字,预计阅读时间需要2分钟。
今天有人要爬取这个网站的资料,网址为:https://ig185.com/mkjw//PCEGG_180/index.。我分析了这个网站的代码,发现它是用structs编写的。然后我分析了网络连接,可以直接调用。
今天有个人要爬取这个网站的数据,地址为:
ig185.com/mkjw/html/PCEGG_180/index.html然后我分析了这个网站的代码,发现这个网站是用structs来写的,然后分析网络连接发现,可以直接调用url:
就可以获取到该网页的数据了,由于数据已经是json的数据,我们用fastjson封装编程类数据,我创建的是maven项目,依赖为:
<!-- mvnrepository.com/artifact/org.apache.ig185.com/kaijiangweb/getHistoryList.do?date=&lotCode=PCEGG_180";String html=pickData(url);
System.out.println(html);
Result result = JSON.parseObject(html, new TypeReference<Result>() {});
System.out.println(result.getMessage());
System.out.println(result.getResult());
List<Lottery> lotteries=result.getResult();
for(Lottery lottery:lotteries){
System.out.println(lottery.toString());
System.out.println(lottery.getPreDrawTime());
}
}
/*
* 爬取网页信息
*/
private static String pickData(String url) {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = httpclient.execute(httpget);
try {
// 获取响应实体
HttpEntity entity = response.getEntity();
// 打印响应状态
if (entity != null) {
return EntityUtils.toString(entity);
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}

