優酷電視劇爬蟲代碼實現一:下載解析視頻網站頁面(2)

來源:互聯網
上載者:User

標籤:spi   nload   content   dmi   下載   還需要   lis   視頻   turn   

1.建立一個電視劇爬蟲入口類StartDSJCount。如果後期還需要綜藝或者電影,也可以仿照再建立綜藝或電影爬蟲入口類。

package com.dajiangtai.djt_spider.start;

import com.dajiangtai.djt_spider.entity.Page;
import com.dajiangtai.djt_spider.service.IDownLoadService;
import com.dajiangtai.djt_spider.service.impl.HttpClientDownLoadService;

/**
* 電視劇爬蟲入口類
* @author Administrator
* 1.在StartDSJCount 中定義頁面下載介面downLoadService

   2.需要對它get/set,這樣在StartDSJCount執行個體化後,可以設定屬性downLoadService,這個介面需要執行個體化,因此,使用set方式對介面進行執行個體化。

   3.添加public Page downloadPage(String url)方法,調用介面this.downLoadService.download(url)方法

   4.main方法中進行測試。
*/
public class StartDSJCount {

//頁面下載介面
private IDownLoadService downLoadService;

public static void main(String[] args) {
StartDSJCount dsj = new StartDSJCount();
dsj.setDownLoadService(new HttpClientDownLoadService());
String url = "http://list.youku.com/show/id_z9cd2277647d311e5b692.html?spm=a2h0j.8191423.sMain.5~5~A!2.iCUyO9";
//下載頁面
Page page = dsj.downloadPage(url);
System.out.println(page.getContent());

}

//下載頁面方法
public Page downloadPage(String url){
return this.downLoadService.download(url);
}

public IDownLoadService getDownLoadService() {
return downLoadService;
}

public void setDownLoadService(IDownLoadService downLoadService) {
this.downLoadService = downLoadService;
}

}

測試結果:

 

 2.定義解析介面IProcessService。這裡是以優酷為例,不同的視頻網站有不同的頁面格式,因此,解析方式也不同。所以,需要實現一個解析介面。

 

package com.dajiangtai.djt_spider.service;

import com.dajiangtai.djt_spider.entity.Page;

/**
* 頁面解析介面
* @author Administrator
*
*/
public interface IProcessService {

public void process(Page page);
}

 

優酷電視劇爬蟲代碼實現一:下載解析視頻網站頁面(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.