Java,jsoup天龙八部畅易阁爬虫

获取角色元宝数量和采矿等级。

 

 

public class Changyige {
	
	public static void main(String[] args) throws InterruptedException  {
		
		
		for (int i =2; i < 22; i++) {
			String htmlAdress = "http://tl.cyg.changyou.com/goods/selling?world_id=5121&world_name=%25E6%25B8%2585%25E6%25AD%258C%25E9%2581%25A5%25E6%259C%259B%25E6%259C%2588&area_name=%25E7%25BA%25B5%25E6%25A8%25AA%25E5%258F%258C%25E7%25BA%25BF&have_chosen=&page_num="+i;
			
			Document doc = null;
			try {
				doc = Jsoup.connect(htmlAdress).get();
			} catch (IOException e) {
				System.out.println(i);
				e.printStackTrace();
			}
			Elements link = doc.select("a");//查找第一个a元素
			Set<String> s = new TreeSet<>();
			for (int j = 0; j < link.size(); j++) {
				String linkHref = link.get(j).attr("href"); // "http://example.com/"//取得链接地址
				//System.out.println(linkHref);
				
				  if(j>=123 && j<=181) { s.add(linkHref); }
			}
			
			
			

			
			for (String address : s) {

				Document docc = null;
				try {
					docc = Jsoup.connect(address).get();
				} catch (IOException e) {
					System.out.println(address);
					e.printStackTrace();
				}
				try {
					//if(getYBCount(docc)>4000 ) {
					//	System.out.println(address);
					//}
					
					if( getLifeCount(docc) >6) {
						System.out.println("    -        "+address);
					}
				} catch (IOException e) {
					
					e.printStackTrace();
				}
				Thread.sleep(1000l);

			}
			Thread.sleep(200l);
			
		}
		
		
		
		
		
	}
	
	//获取元宝数量
	public static int getYBCount(Document doc) throws IOException {
		//201909212135597616
		
		
		Elements links = doc.getElementsByClass("row2");
		String linkText = links.get(29).text();
		int count = Integer.valueOf(linkText.substring(5));
		return count;
	}
	
	
	//获取采矿等级
	public static int getLifeCount(Document doc) throws IOException{
		
		Elements elements = doc.getElementsByTag("script");
		
		String text = elements.get(8).data();
		Document document = Jsoup.parse(text);
		Elements links = document.getElementsByClass("method-info");
		String text2 = links.get(links.size()-6).text();
		int level = Integer.valueOf(text2.substring(6));
		return level;
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值