java爬取某電影網站資料
阿新 • • 發佈:2019-02-11
使用jsoup獲取動態網站的資料
部分程式碼:
/**
* 獲取分類的所有相對連結地址 和名稱,儲存到map中,返回資料
*
*/
public class GetMoviesName {
private String url;
HashMap<String, String> hrefandname = new HashMap<String, String>();
public GetMoviesName(String url) {
this.url = url;
}
public HashMap<String, String> getAllKinds () throws IOException{
Document kinds = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36")
.timeout(10000)
.get();
Elements elements = kinds.select("#content .types a" );
for(Element element : elements){
String kindurl = element.attr("href");
hrefandname.put(kindurl, element.text());
}
return hrefandname;
}
}
try {
//獲取該類別影片的數量total、可線上觀看數量playable_count
document = Jsoup.connect(finalurl).timeout (10000).ignoreContentType(true).execute().body();
// document------{"playable_count":18,"total":32,"unwatched_count":32}可線上觀看18部,共32部,未觀看32部
} catch (IOException e) {
e.printStackTrace();
}
private int id;
private String name;
private String types;
private String release_date;
private double score;
private String url;
private String is_playable;