写作的目的
好久没有写博客了,最近一段时间比较忙,总是在讨论公司的业务逻辑去了,技术落下了一大堆了,好了,不扯了,说说今天的主题吧。最近利用晚上的时间,使用Fiddler抓包,把InfoQ、ITEye、CSDN、泡在网上的日子,开源中国,获得了一些数据,然后整理了一下,为了练手做了个小App。先看看成果吧:
抓包
我一般也就是使用Fidder,相信很多人都用过吧,具体页面如下,具体的方法大家也就百度吧,这个操作比较简单:
比如我抓的泡在网上的日子 http://www.jcodecraeer.com/中网站数据:
使用Fiddler抓包:
抓完包之后,我们需要记录它的地址和分页的参数:
这个蛮重要的,因为我们在客户端使用的最多的就是分页数据了。下面是我爬出的记录,菜鸟爬的,大神勿喷:
infoQ :
架构:http://www.infoq.com/cn/architecture-design/articles/
移动:http://www.infoq.com/cn/mobile/articles/
云计算:http://www.infoq.com/cn/cloud-computing/articles/
大数据:http://www.infoq.com/cn/bigdata/articles/
运维:http://www.infoq.com/cn/operation/articles/
ITEYE:
资讯:http://www.iteye.com/news
精华:http://www.iteye.com/magazines
博客:http://www.iteye.com/blogs
专栏:http://www.iteye.com/blogs/subjects
CSDN
前端
http://geek.csdn.net/service/news/get_category_news_list?category_id=frontend&jsonpcallback=jQuery20309836559783031329_1479717830080&username=u013762572&from=20&size=20&type=category&_=1479717830081
移动
http://geek.csdn.net/service/news/get_category_news_list?category_id=mobile&jsonpcallback=jQuery20301528046427485552_1479717874823&username=u013762572&from=0&size=20&type=category&_=1479717874824
云计算
http://geek.csdn.net/service/news/get_category_news_list?category_id=cloud&jsonpcallback=jQuery20307511375457787082_1479717658917&username=u013762572&from=20&size=20&type=category&_=1479717658918
大数据
http://geek.csdn.net/service/news/get_category_news_list?category_id=bigdata&jsonpcallback=jQuery20307133938887790177_1479717696246&username=u013762572&from=20&size=20&type=category&_=1479717696247
数据库
http://geek.csdn.net/service/news/get_category_news_list?category_id=database&jsonpcallback=jQuery20307188289349209822_1479717786436&username=u013762572&from=20&size=20&type=category&_=1479717786437
泡在网上的日子:
综合资讯:http://www.jcodecraeer.com/plus/list.php?tid=4
程序设计:http://www.jcodecraeer.com/plus/list.php?tid=6
安卓开发:http://www.jcodecraeer.com/plus/list.php?tid=16
前端开发:http://www.jcodecraeer.com/plus/list.php?tid=5
IOS开发: http://www.jcodecraeer.com/plus/list.php?tid=27
OSC:
全部:https://www.oschina.net/action/ajax/get_more_recommend_blog?classification=0&p=2
移动 https://www.oschina.net/action/ajax/get_more_recommend_blog?classification=428602&p=2
前端:https://www.oschina.net/action/ajax/get_more_recommend_blog?classification=428612&p=2
服务器:https://www.oschina.net/action/ajax/get_more_recommend_blog?classification==428640&2
游戏开发:https://www.oschina.net/action/ajax/get_more_recommend_blog?classification=429511&p=2
编程语言:https://www.oschina.net/action/ajax/get_more_recommend_blog?classification=428609&p=2
解析
由于我们获取的数据是Html字符串,我使用的是Jsoup类[主要是大java比较牛逼啊],使用Jsoup将字符串转化为Html中Dom对象,然后对Dom对象进行操作,对于Jsoup类的我也就不多讲了,主要是比较简单,这篇文章讲得比较详细:链接 举个例子,请求到开源中国的接口时:
使用Crtl+U查看源码:
然后使用Jsoup解析:
Document document = Jsoup.parse(htmlStr);
Elements rootElements = document.getElementsByClass("item");
if (null != rootElements && !rootElements.isEmpty()) {
Blog blog;
for (Element e : rootElements) {
blog = new Blog();
String photo = e.getElementsByClass("box-fl").get(0).select("img").attr("data-delay");
Element target = e.getElementsByClass("box-aw").get(0);
String title = target.select("a").get(0).text();
String link = target.select("a").get(0).attr("href");
String desc = target.select("section").get(0).text();
Element footerElement = target.select("footer").get(0);
String publishTime = footerElement.select("span").get(0).text();
String author = footerElement.select("span").get(2).text();
LogUtils.d("title:" + title);
LogUtils.d("link:" + link);
LogUtils.d("desc:" + desc);
LogUtils.d("publishTime:" + publishTime);
LogUtils.d("author:" + author);
LogUtils.d("photo:" + photo);
blog.title = title;
blog.link = link;
blog.description = ComUtils.cutOffString(desc, 120);
blog.publishTime = publishTime;
blog.author = author;
blog.articleType = ArticleType.OSCHINA;
blog.photo = photo;
blog.hasRead = DBDataUtils.userHasReadArticle(title);
blog.hasCollect = DBDataUtils.userHasCollection(title);
_blogList.add(blog);
}
}
}
然后得出的结论为:
android客户端
好了 我们没有接口,但是我们还是获得了数据流,哈哈,这个比较好玩了。现在我们就来搞android客户端了。
采用了Retrofit2.0 + OkHttp3.0作为网络请求,
使用RxJava创建类似EventBus请求案例,
使用了ormlite保存阅读记录和收藏记录,
使用了Tencent的X5 webview内核,
使用了glide管理图片,
使用了Bufferknife代替findviewById
使用了PhotoView管理webView中详情图片缩放
……
基本上代码结构为:
代码已经到了git上了,这是我的第一个git项目,希望大家给点鼓励,我是新人,我需要被鼓励,我也需要star,呵呵。。。
结语
还是那句话,公司的破业务比较多,刚刚毕业的苦逼程序员经常被教训,所以每天还要学习其他知识,比较累,也很坑壁,所以还有很多功能暂时没有加上,毕竟才花了半个月不到的时间,希望大家不要介意,我也只是刚刚在路上,这个项目我也会持续维护,最后感谢陪伴我的那些人,特别是年少的风,AndroidFire,是他们的鼓励才让我这个菜鸟感到我们还是有希望的,谢谢:
这是我的git地址,https://github.com/Microhx/MicroBlog 。谢谢大家。