jsoup 效果
qq新闻 内容抓取 正则表达 (正则)
http://knight-black-bob.iteye.com/blog/2312411
比较 tika 和正则 ,我更喜欢jsoup
正则 比较难写 ,, ,,,,
下面有jar 包下载
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.9.2</version>
</dependency>
IteyeItemEntity [ userName=wosyingjun, userPicLink=http://www.iteye.com/upload/logo/user/1184026/fa9a8493-f9a7-3e3b-9630-12ad8f65d277-thumb.png?1467599214, userBlogLink=http://wosyingjun.iteye.com, title=推荐几个自己写的Java后端相关的范例项目, content=推荐几个自己写的范例项目 这里推荐几个自己写的范例项目,主要采用SSM(Spring+SpringMVC+Mybatis)框架,分布式架构采用的是(dubbo+zookeeper)。范例项目的好处是简单易懂,在架构一个新的项目的时候可以直接当成脚手架来用,方便快速开发,另外项目中涉及到以及未来可能涉及到的知识点都会不断完善。 三个项目是互相发展而来的,目前仍在不断完善中,依次为: ..., articleLink=http://wosyingjun.iteye.com/blog/2312553, seeNum=有2871人浏览, goodNum=7顶, badNum=0踩, insertTime=2016-07-21 09:04 ] //Connection connection = Jsoup.connect(url); //Document document = connection.get(); Document document = Jsoup.parse(data); Elements indexmain = document.select(".blog"); Iterator<Element> blogIter = indexmain.iterator(); IteyeItemEntity item = null; while (blogIter.hasNext()) { Element element = blogIter.next(); String userName = element.select(".content .blog_info a[title]").text(); String userPicLink = element.select(".content .logo img").attr("src"); String userBlogLink = element.select(".content .blog_info a").attr("href"); String title = element.select(".content h3 a[title]").text(); String content = element.select(".content div").iterator().next().text(); String articleLink = element.select(".content h3 a").last().attr("href"); String seeNum = element.select(".content .blog_info .view").text(); String goodNum = element.select(".content .blog_info .digged .digg").text(); String badNum = element.select(".content .blog_info .digged .bury").text(); String insertTime = element.select(".content .blog_info .date").text(); item = new IteyeItemEntity(userName, userPicLink, userBlogLink, title, content, articleLink, seeNum, goodNum, badNum, insertTime); list.add(item);
package com.couriousby.iteyedemo.util; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.jsoup.Connection; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import android.util.Log; import android.widget.Toast; import com.couriousby.iteyedemo.MyApplication; import com.couriousby.iteyedemo.entity.IteyeItemEntity; /** * @author baoyou E-mail:curiousby@163.com * @version 2016-7-22 上午10:58:49 * * desc: ... */ public class IteyeJsoupPerformer { public static List<IteyeItemEntity> getListIteyeEntity(String data){ List<IteyeItemEntity> list = new ArrayList<IteyeItemEntity>(); try{ //Connection connection = Jsoup.connect(url); //Document document = connection.get(); Document document = Jsoup.parse(data); Elements indexmain = document.select(".blog"); Iterator<Element> blogIter = indexmain.iterator(); IteyeItemEntity item = null; while (blogIter.hasNext()) { Element element = blogIter.next(); String userName = element.select(".content .blog_info a[title]").text(); String userPicLink = element.select(".content .logo img").attr("src"); String userBlogLink = element.select(".content .blog_info a").attr("href"); String title = element.select(".content h3 a[title]").text(); String content = element.select(".content div").iterator().next().text(); String articleLink = element.select(".content h3 a").last().attr("href"); String seeNum = element.select(".content .blog_info .view").text(); String goodNum = element.select(".content .blog_info .digged .digg").text(); String badNum = element.select(".content .blog_info .digged .bury").text(); String insertTime = element.select(".content .blog_info .date").text(); item = new IteyeItemEntity(userName, userPicLink, userBlogLink, title, content, articleLink, seeNum, goodNum, badNum, insertTime); list.add(item); } }catch(Exception e){ e.printStackTrace(); } return list; }
package com.couriousby.iteyedemo.util; import java.util.ArrayList; import java.util.List; import com.couriousby.iteyedemo.R; import com.couriousby.iteyedemo.entity.GridEntity; /** * @author baoyou E-mail:curiousby@163.com * @version 2016-7-22 下午1:10:55 * * desc: ... */ public class Constants { final static String URL_BASE = "http://www.iteye.com/blogs"; public static String getIteyeCategory(int category ) { switch (category) { case 0: return ""; case 1: return "/category/mobile"; case 2: return "/category/web"; case 3: return "/category/architecture"; case 4: return "/category/language"; case 5: return "/category/internet"; case 6: return "/category/opensource"; case 7: return "/category/os"; case 8: return "/category/database"; case 9: return "/category/develop"; case 10: return "/category/industry"; case 11: return "/category/other"; default: return ""; } } public static String getIteyeUrl(int category,int page) { return URL_BASE + getIteyeCategory(category)+"?page="+page; } public static List<GridEntity> getGridItem() { List<GridEntity> list = new ArrayList<GridEntity>(); list.add(new GridEntity(0, "全部分类", R.drawable.iteye_all, 0)); list.add(new GridEntity(1, "移动开发", R.drawable.iteye_mobile, 1)); list.add(new GridEntity(2, "web前端", R.drawable.iteye_web, 2)); list.add(new GridEntity(3, "企业架构", R.drawable.iteye_architecture, 3)); list.add(new GridEntity(4, "编程语言", R.drawable.iteye_language, 4)); list.add(new GridEntity(5, "互联网", R.drawable.iteye_internet, 5)); list.add(new GridEntity(6, "开源软件", R.drawable.iteye_opensource, 6)); list.add(new GridEntity(7, "操作系统", R.drawable.iteye_os, 7)); list.add(new GridEntity(8, "数据库", R.drawable.iteye_database, 8)); list.add(new GridEntity(9, "研发管理", R.drawable.iteye_develop, 9)); list.add(new GridEntity(10, "行业应用", R.drawable.iteye_industry, 10)); list.add(new GridEntity(11, "非技术", R.drawable.iteye_other, 11)); return list; } }
package com.couriousby.iteyedemo.activity; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.LinearLayout.LayoutParams; import android.widget.GridView; import android.widget.PopupWindow; import android.widget.TextView; import com.couriousby.iteyedemo.MyApplication; import com.couriousby.iteyedemo.R; import com.couriousby.iteyedemo.adapter.IteyeAdapter; import com.couriousby.iteyedemo.adapter.IteyePopwindowGridListAdapter; import com.couriousby.iteyedemo.entity.GridEntity; import com.couriousby.iteyedemo.entity.IteyeItemEntity; import com.couriousby.iteyedemo.listener.OnIteyeGridViewItemclickListener; import com.couriousby.iteyedemo.quote.xlistview.MsgListView; import com.couriousby.iteyedemo.quote.xlistview.MsgListView.IXListViewListener; import com.couriousby.iteyedemo.request.event.IteyeStringHttpEvent; import com.couriousby.iteyedemo.request.event.base.RequestEvent; import com.couriousby.iteyedemo.request.http.IteyeHttpRequest; import com.couriousby.iteyedemo.util.Constants; import com.couriousby.iteyedemo.util.IteyeJsoupPerformer; import de.greenrobot.event.EventBus; public class IteyeMainActivity extends Activity implements IXListViewListener ,OnItemClickListener,OnClickListener,OnIteyeGridViewItemclickListener{ final static String ITEYE_DETAIL_URL = "iteye_detail_url"; private static int start = 1; private static int category = 0; private Context mContext; private MsgListView mListView; private List<IteyeItemEntity> mDataList; private IteyeAdapter mAdapter; private TextView mTopChooseBar; private PopupWindow mPopupWindow; private IteyePopwindowGridListAdapter gridAdapter; private GridView gridView; private List<GridEntity> mGridList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.iteye_list); this.mContext = IteyeMainActivity.this; initUtils(); initView( ); initListeners(); EventBus.getDefault().register( this ); start =1; category=0; IteyeHttpRequest.getIteyeDate(category, start); } private void initUtils() { mDataList = new ArrayList<IteyeItemEntity>(); mAdapter = new IteyeAdapter(mContext); mAdapter.setmDataList(mDataList); mGridList = Constants.getGridItem(); gridAdapter = new IteyePopwindowGridListAdapter(mContext); gridAdapter.setOnIteyeGridViewItemclickListener(this); gridAdapter.setmList(mGridList); } private void initView() { mListView = (MsgListView) this.findViewById(R.id.qq_news_list); mListView.setAdapter(mAdapter); View baseView = View.inflate( this, R.layout.iteye_topbar, null ); mTopChooseBar = (TextView) this.findViewById( R.id.tv_iteye_topbar); mPopupWindow = new PopupWindow(baseView ,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, false ); mPopupWindow.setBackgroundDrawable( new BitmapDrawable() ); mPopupWindow.setOutsideTouchable( true ); mPopupWindow.setFocusable( true ); gridView = (GridView) baseView.findViewById(R.id.iteye_gr_mlist); gridView.setAdapter(gridAdapter); } private void initListeners() { mTopChooseBar.setOnClickListener(this); mListView.setPullLoadEnable(true); mListView.setPullRefreshEnable(true); mListView.setXListViewListener(this); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(this); gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); } @Override public void onDestroy() { EventBus.getDefault().unregister( this ); super.onDestroy(); } public void onEventMainThread(RequestEvent requestEvent){ if(requestEvent instanceof IteyeStringHttpEvent){ IteyeStringHttpEvent event = (IteyeStringHttpEvent) requestEvent; switch(event.status){ case HTTP_ERROR: mListView.stopRefresh(); mListView.stopLoadMore(); mListView.setPullLoadEnable(false); break; case HTTP_START: { mListView.stopRefresh(); mListView.stopLoadMore(); String result = event.data; mAdapter.clearMDataList(); List<IteyeItemEntity> list = IteyeJsoupPerformer.getListIteyeEntity(result); mAdapter.setmDataList(list); mAdapter.notifyDataSetChanged(); } break; case HTTP_SUCCESS: { mListView.stopRefresh(); mListView.stopLoadMore(); String result = event.data; mAdapter.clearMDataList(); List<IteyeItemEntity> list = IteyeJsoupPerformer.getListIteyeEntity(result); mAdapter.addMDataList(list); mAdapter.notifyDataSetChanged(); } break; default: break; } }else{ } } @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { IteyeItemEntity item = mAdapter.getItem(position - 1 ); if (item != null) { Intent msgIntent = new Intent(); Bundle bundle = new Bundle(); // Bundle的底层是一个HashMap<String, Object bundle.putString(IteyeMainActivity.ITEYE_DETAIL_URL, item.getArticleLink() ); msgIntent.putExtra("bundle", bundle); msgIntent.setClass(MyApplication.newInstance(), IteyeDetailActivity.class); startActivityForResult( msgIntent, 1000 ); } } @Override public void onRefresh() { start =1; mListView.setPullLoadEnable(true); mListView.setPullRefreshEnable(true); IteyeHttpRequest.getIteyeDate(category, start); } @Override public void onLoadMore() { start += 1; IteyeHttpRequest.getIteyeDate(category, start); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.tv_iteye_topbar: if (mPopupWindow.isShowing()) { mPopupWindow.dismiss(); } else { mPopupWindow.showAsDropDown(view); } break; default: break; } } @Override public void OnIteyeGridViewItemclick(GridEntity item) { mTopChooseBar.setText(item.getName() ); mPopupWindow.dismiss(); start = 1; category = item.getId(); IteyeHttpRequest.getIteyeDate(category, start); } }
package com.couriousby.iteyedemo.request.http; import com.android.volley.Response.ErrorListener; import com.android.volley.Response.Listener; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import com.couriousby.iteyedemo.MyApplication; import com.couriousby.iteyedemo.request.manager.IteyeHttpManager; import com.couriousby.iteyedemo.util.Constants; public class IteyeHttpRequest { public static void getIteyeDate(int catgory ,final int page){ String url = Constants.getIteyeUrl(catgory,page); StringRequest request = new StringRequest(url, new Listener<String>() { @Override public void onResponse(String response) { if (page ==1 ) IteyeHttpManager.getIteyeByPageFirst(response); else IteyeHttpManager.getIteyeByPage(response); } }, new ErrorListener() { @Override public void onErrorResponse(VolleyError error) { IteyeHttpManager.getIteyeByPageError(); } }) /* { @Override protected Response<String> parseNetworkResponse( NetworkResponse response) { String str = null; try { str = new String(response.data,"utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return Response.success(str, HttpHeaderParser.parseCacheHeaders(response)); } }*/ ; Volley.newRequestQueue(MyApplication.newInstance()).add(request); } }
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
使用就jsoup写的爬虫,用于爬取网站的磁力链接
10. **版本更新**:Tika项目持续发展,新版本会添加对更多文件格式的支持,修复已知问题,以及改进性能和稳定性。保持对最新版本的关注和升级,能确保最佳的使用体验。 总之,Tika是Java开发中一个不可或缺的工具,...
tika-python 绑定到 Apache Tika REST 服务 Python binding to the Apache Tika REST services Apache Tika 库的 Python 端口,可使用 Tika REST 服务器使 Tika 可用。这使得 Apache Tika 可作为 Python 库使用,可...
Apache Tika是一款强大的内容检测和元数据提取工具,主要用于从各种文件格式中抽取文本和元数据。这个"tika读取文件专用包"显然包含了Tika项目所需要的各种jar包,这些jar包支持处理多种文件类型,如PDF、DOC、XLS、...
Apache Tika是一个强大的开源工具,专门用于从各种文件格式中提取元数据和文本内容。它在信息技术领域,尤其是在搜索引擎和内容分析应用中扮演着重要角色。"apache-tika-0.1-incubating-src.tar.gz"是Apache Tika...
如果需要处理现代的文件格式或者更全面的功能,建议升级到较新版本的Tika,如Tika 1.x系列,它们通常会提供更好的性能和更多的文件格式支持。同时,随着技术的发展,新的安全问题可能会被发现,使用较旧版本的库可能...
Tika是一个强大的Apache项目,主要用于从各种文件格式中提取元数据和内容。它是一个内容分析工具,能够识别和解析超过500种不同的文件类型,包括文档、图像、音频和视频文件。在Java环境中,Tika是通过JAR(Java ...
Apache Tika本产品包括在以下位置开发的软件Apache软件基金会。版权所有1993-2010大学大气研究公司/ Unidata该软件包含源自UCAR / Unidata的NetCDF库的代码。Tika服务器组件使用CDDL许可的依赖项
Tika和Lucene是两个非常重要的Java库,广泛应用于信息提取和全文检索领域。这个压缩包包含"tika-app-1.20.jar"和"lucene-7.7.1",它们分别是Apache Tika和Apache Lucene的特定版本。 Apache Tika是一个内容分析工具...
Apache Tika是一个强大的开源内容检测和解析库,主要用于从各种文件格式中提取元数据和文本。这个名为“tika1.4.zip”的压缩包包含了Tika的1.4版本源代码,这对于开发者来说是一个宝贵的资源,可以深入理解其内部...
Apache Tika是一个强大的内容检测和元数据提取库,主要用于解析各种不同格式的文件。它被广泛应用于信息检索、文本挖掘和内容分析等领域...通过了解和掌握Tika的使用,开发者可以更好地处理和利用各种类型的数据资源。
对于HTML文档,Tika结合了Jsoup和NekoHTML等库,确保能够正确解析HTML标签和属性,并将内容提取出来。 对于微软格式的文档,Tika主要依赖Apache POI库。POI是专门用于处理Microsoft Office文件格式的Java库,包括...
Apache Tika 利用现有的解析类库,从不同格式的文档中(例如HTML, PDF, Doc),侦测和提取出元数据和结构化内容。 功能包括: 侦测文档的类型,字符编码,语言,等其他现有文档的属性。 提取结构化的文字内容。...
tika最新版本,tika-app-1.0.jar,提取office和pdf文档内容
Apache Tika 1.1 所需要的jar包,方便不想用maven的同学. 此压缩包内是核心jar包,依据http://tika.apache.org/1.1/gettingstarted.html 中Using Tika in an Ant project章节列出的 classpath 找齐 部分版本比文章中...
Apache Tika是一款强大的内容检测和元...总的来说,"apache-tika-1.0-src.zip"是学习和定制Tika的重要资料,可以帮助开发者深入理解其内部机制,从而更好地利用Tika在信息提取、内容分析和搜索引擎构建等领域发挥效能。
在本篇博文中,“跟益达学Solr5之使用Tika从PDF中提取数据导入索引”,我们将探讨如何利用Apache Solr 5和Tika这两个强大的开源工具,从PDF文档中抽取数据并将其有效地导入到Solr索引库中。Apache Solr是一款功能...
Tika1.0jar包和源码 Lucene从各种文件类型中提取文字信息的工具