爬取静态页面
需求:获取本人博客页面的 title “yhao的博客- 博客频道 - CSDN.NET”
首先通过okhttp以get方式请求页面:
final String url = "http://blog.csdn.net/yhaolpz?viewmode=contents";
Request request = new Request.Builder()./service/https://blog.csdn.net/url(url).build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, "onFailure ");
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.code() == 200) {
String html = response.body().string();
Log.d(TAG, "onResponse: " + html);
}
}
});
返回页面数据onResponse如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="

本文介绍了如何在Android上进行网页爬虫操作,包括使用Jsoup抓取静态页面的title,以及通过PhantomJS处理动态加载的内容。在静态页面抓取中,重点讲解了Jsoup的使用步骤,而动态页面抓取部分则探讨了如何利用PhantomJS模拟浏览器行为,抓取ajax动态注入的数据。
240

被折叠的 条评论
为什么被折叠?



