爬虫,抓取优快云某用户的信息

该篇博客介绍了如何使用Java和Jsoup库抓取优快云上特定用户的个人信息,包括姓名、头像、简介和文章统计。展示了Test优快云类中针对不同用户ID进行信息获取的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package zp;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

/**
* @author 作者:tony chan
* @email 邮箱:chenzs@tedu.cn
* @version v.1.0 创建时间:上午9:47:50
* @description 描述:抓取优快云某用户的信息
*/

public class Test优快云 {
	public static void main(String[] args) throws IOException {
		String[] urls = {"weixin_43884234","u012932876","qq_16804847","maitian_2008","weixin_38305440","nutony","weixin_46595435"};
		String[] names = {"程晓宇","刘沛霞","刘昱江","齐雷","王海涛","陈子枢","新人"};
		for(int i = 0; i<urls.length; i++) {
			优快云 csdn = Test优快云.csdn(names[i], "https://blog.youkuaiyun.com/" + urls[i]);
			System.out.println(csdn.order());
		}
	}
	
	public static 优快云 csdn(String name, String url) throws IOException {
		优快云 csdn = new 优快云();
		Document doc = Jsoup.connect(url).get();
		csdn.name = doc.select(".user-profile-head-name").get(0).text()+" ("+name+")";
		csdn.image = doc.select(".user-profile-avatar").select("img").get(0).attr("src");
		csdn.info = doc.select(".user-profile-head-info-r-c").get(0).text();
		
		//1,190,760 被访问 141 原创 1,527 排名 7,143 粉丝
		csdn.orderNo = csdn.info.substring(csdn.info.indexOf("原创")+3, csdn.info.indexOf("排名") );
		
		try {
			csdn.intro = doc.select(".introduction-fold").select(".default").get(0).text();
		}catch(Exception e) {}
		
		return csdn;
	}
}

class 优快云{
	String name;
	String orderNo;
	String image;
	String info;
	String intro;
	
	@Override
	public String toString() {
		return "优快云 [name=" + name + ", info=" + info + ", intro=" + intro + ", image=" + image + "]";
	}
	
	public String order() {
		return "优快云 [name=" + name + ", order=" + orderNo + "]";
	}	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值