百度360必应搜狗淘宝本站头条
当前位置:网站首页 > IT技术 > 正文

jsoup 抓取 iteye 网站_js抓取网页内容

wptr33 2025-02-20 18:17 16 浏览

jsoup 效果

http://knight-black-bob.iteye.com/blog/2312411

比较 tika 和正则 ,我更喜欢jsoup

正则 比较难写 ,, ,,,,

下面有jar 包下载

org.jsoup

jsoup

1.9.2

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 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 getListIteyeEntity(String data){
		List list = new ArrayList;
		try{ 
			//Connection connection = Jsoup.connect(url);  
			//Document document = connection.get; 
			Document document = Jsoup.parse(data); 
			Elements indexmain = document.select(".blog");
			 Iterator 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 getGridItem {
		List list = new ArrayList;
		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 mDataList;
	private IteyeAdapter mAdapter;
	
	
	 private TextView mTopChooseBar;
	 private PopupWindow mPopupWindow;
	 
	 
	 private IteyePopwindowGridListAdapter gridAdapter;
	 private GridView gridView;
	 private List 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;
		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 list = IteyeJsoupPerformer.getListIteyeEntity(result);
					mAdapter.setmDataList(list);
					mAdapter.notifyDataSetChanged; 
					 
					   
				}
				break;
				case HTTP_SUCCESS: {   
					mListView.stopRefresh; 
					mListView.stopLoadMore;
					String result = event.data;
					mAdapter.clearMDataList;
					 List 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

相关推荐

VPS主机搭建Ghost环境:Nginx Node.js MariaDB

Ghost是一款个人博客系统,它是使用Node.js语言和MySQL数据库开发的,同时支持MySQL、MariaDB、SQLite和PostgreSQL。用户可以在支持Node.js的服务器上使用自己...

centos7飞速搭建zabbix5.0并添加windows、linux监控

一、环境zabbix所在服务器系统为centos7,监控的服务器为windows2016和centos7。二、安装zabbix官方安装帮助页面...

Zabbix5.0安装部署

全盘展示运行状态,减轻运维人员的重复性工作量,提高系统排错速度,加速运维知识学习积累。1.png...

MariaDB10在CentOS7系统下,迁移数据存储位置

背景在CentOS7下如果没有默认安装MySQL数据库,可以选择安装MariaDB,最新的版本现在是10可以选择直接yum默认安装的方式yum-yinstallmariadbyum-yi...

frappe项目安装过程

1,准备一台虚拟机,debian12或者ubuntusever22.04.3可以用virtualbox/qemu,或者你的超融合服务器安装一些常用工具和依赖库我这里选择server模式安装,用tab...

最新zabbix一键安装脚本(基于centos8)

一、环境准备注意:操作系统必须是centos8及以上的,因为我配的安装源是centos8的。并且必须连接互联网,脚本是基于yum安装的!!!...

ip地址管理之phpIPAM保姆级安装教程 (原创)

本教程基于Ubuntu24.04LTS,安装phpIPAM(最新稳定版1.7),使用Apache、PHP8.3和MariaDB,遵循最佳实践,确保安全性和稳定性。一、环境准备1....

centos7傻瓜式安装搭建zabbix5.0监控服务器教程

zabbix([`zaebiks])是一个基于WEB界面的提供分布式系统监视...

zabbix7.0LTS 保姆级安装教程 小白也能轻松上手安装

系统环境:rockylinux9.4(yumupdate升级到最新版本)数据库:mariadb10.5.22第一步:关闭防火墙和selinux使用脚本关闭...

ubuntu通过下载安装包安装mariadb10.4

要在Ubuntu18.04上安装MariaDB10.4.34,用的是那个tar.gz的安装包。步骤大概是:...

从0到1:基于 Linux 快速搭建高可用 MariaDB Galera 集群(实战指南)

在企业生产环境中,数据库的高可用性至关重要。今天带你从0到1,手把手在Linux系统上快速搭建一个高可用MariaDBGaleraCluster,实现数据库同步复制、故障自动恢复,保障业务...

Windows 中安装 MariaDB 数据库

mariadb在Windows下的安装非常简单,下载程序双击运行就可以了。需要注意:mariadb和MySQL数据库在Windows下默认是不区分大小写的,但是在Linux下是区分...

SQL执行顺序(SqlServer)

学习SQL这么久,如果突然有人问你SQL的执行顺是怎么样的?是不是很多人会觉得C#、JavaScript都是根据编程顺序来处理的,那么SQL也是根据编程顺序来执行的吗?...

C# - StreamWriter与StreamReader 读写文件 101

读写文本文件的方式:1)File静态类的File.ReadAllLines();与File.WriteAllLines();方法进行读写...

C#中的数组探究与学习

C#中的数组一般分为:...