博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
爬虫篇——采集单机游戏(网页游戏),爬取小游戏
阅读量:3907 次
发布时间:2019-05-23

本文共 3432 字,大约阅读时间需要 11 分钟。

接到需求,要求要将几个好玩的网页版本的单机小游戏。采集到我们的服务器中。

这里以 水枪射手 这个游戏举例

在这里插入图片描述
1、首先准备好抓包工具或者直接在用浏览器自带的抓包,推荐用抓包工具可以批量复制抓到的资源链接。
如chrome浏览器:
在这里插入图片描述

fiddler抓包工具:

在这里插入图片描述
2、抓包工具准备好后,然后开始玩一遍游戏,在玩游戏的时候通过抓包工具,抓取游戏的资源链接。 需要注意的是,有的游戏,在刚进去的时候会吧所有的资源链接都加载出来,而有的游戏则需要一边玩,一边加载新的资源链接。

将抓取的资源链接,复制到代码里。去下载

public static void main(String[] args) {
//存到自己的文件夹位置 String localPath="D:/crawler_games/shoot/"; //pre_url 这个参数是:用于存文件夹时候,去掉链接的前面这一串路径 String pre_url="http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/"; String list[]={
//"这里输入抓包的所有代码 " "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/gameIndex.html", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/h5api-interface.php", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/index.js", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/libs/laya.core.js", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/libs/laya.ui.js", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/libs/laya.d3.js", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/libs/laya.physics3D.js", "http://flash.7k7k.com/cms/cms10/20200116/1213129483/01/js/bundle.js", //"这里输入抓包的所有代码...上面这些只是小部分示例" }; try {
for (String s : list) {
String urlName = s.replace(pre_url,""); String path=localPath+urlName; downloadNet(s,path,localPath,pre_url); } } catch (Exception e) {
e.printStackTrace(); } } //下载资源文件的方法 private static void downloadNet(String crawlerUrl,String path,String localPath,String pre_url) throws Exception {
if (!crawlerUrl.contains(pre_url)){
return; } //这里的将首页资源,刚换名字 if(path.contains("gameIndex.html")){
path=localPath+"\\index.html"; } System.out.println("完成 :" +path); // 下载网络文件 int bytesum = 0; int byteread = 0; URL url = new URL(crawlerUrl); String[] split = path.split("\\/"); System.out.println("长度"+split.length); for (int i = 1; i < split.length; i++) {
String everyPath=""; for (int j = 0; j < i; j++) {
everyPath+=split[j]+"/"; File f = new File(everyPath); //没有目录,就创建目录 if (!f.exists()) {
try {
f.mkdirs(); } catch (Exception e) {
e.printStackTrace(); } } } } try {
URLConnection conn = url.openConnection(); InputStream inStream = conn.getInputStream(); FileOutputStream fs = new FileOutputStream(path); byte[] buffer = new byte[1204]; int length; while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; fs.write(buffer, 0, byteread); } } catch (FileNotFoundException e) {
e.printStackTrace(); } catch (IOException e) {
e.printStackTrace(); } }

3、执行main方法采集:

在这里插入图片描述

4、执行完后,就可以看到采集的文件资源了(从自己指定的目录里查看)

在这里插入图片描述
5、通过本地的环境的nginx就可以访问自己的抓的小游戏了, nginx做个简单的配置,配置静态资源访问即可(注意:游戏的资源后缀比较多、且少见,按后缀配置静态资源访问的时候,一定保证这些资源都可以正常访问):
在这里插入图片描述
6、一切准备好后,可以访问自己本地的游戏链接了

在这里插入图片描述

转载地址:http://vomen.baihongyu.com/

你可能感兴趣的文章
HDU 1003 Max Sum
查看>>
Code Vs 1014 装箱
查看>>
循环队列,队链的实现
查看>>
HDU 2602 Bone Collector (01背包)
查看>>
POJ 1837 Blance (01背包)
查看>>
HDU 2456 饭卡 (01背包)
查看>>
HDU 1559 最大子矩阵
查看>>
Open Judge 4010 :2011
查看>>
百练OJ-2815 城堡问题【DFS】
查看>>
CODE[VS] 1025 选菜 【背包】
查看>>
POJ 1724 ROADS【DFS+剪枝】
查看>>
AOJ 847 整数拆段
查看>>
AOJ 848 分数拆分
查看>>
UVA 133 The Dole Queue 【约瑟夫环】
查看>>
XDOJ 1208 B.笑爷买房 【DFS】
查看>>
部门年度工作总结的内容
查看>>
pandas学习笔记
查看>>
Numpy笔记
查看>>
正则表达式
查看>>
python线程进程笔记
查看>>