| | |
| | | public static String baseUrl = "https://movie.douban.com/subject_search?cat=102&"; |
| | | public static int maxCount = 1; |
| | | |
| | | /** |
| | | * @title: |
| | | * @description: 搜索 |
| | | * @author Administrator |
| | | * @date 2021/9/22 17:46 |
| | | */ |
| | | public static List<VideoInfo> startSearch(String st) throws IOException { |
| | | Document doc = Jsoup |
| | | .connect( |
| | |
| | | area = ist.substring(start + 7, ist.length()) |
| | | .replace("\"", "").trim(); |
| | | System.out.println(area); |
| | | }catch(Exception e) |
| | | { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | break; |
| | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private static DouBanStar getStarInfo(Element item) { |
| | | DouBanStar star = new DouBanStar(); |
| | | String avatarStyle = item.getElementsByClass("avatar").get(0).attr("style"); |
| | | String avatar = avatarStyle.replace("background-image: url(", "").replace(")", "").trim(); |
| | | String name = item.getElementsByTag("a").get(0).attr("title"); |
| | | if (name.contains(" ")) { |
| | | String chaineseName = name.split(" ")[0].trim(); |
| | | String englishName = name.substring(chaineseName.length()).trim(); |
| | | star.setChineseName(chaineseName); |
| | | star.setEnglishName(englishName); |
| | | } |
| | | |
| | | String href = item.getElementsByTag("a").get(0).attr("href"); |
| | | if (href.endsWith("/")) |
| | | href = href.substring(0, href.length() - 1); |
| | | String[] sts = href.split("/"); |
| | | String id = sts[sts.length - 1]; |
| | | if (!avatar.contains("default")) |
| | | star.setAvatar(avatar); |
| | | star.setId(id); |
| | | star.setUrl(href); |
| | | return star; |
| | | } |
| | | |
| | | private static List<DouBanStar> getStarList(Element root) { |
| | | Elements items = root.getElementsByTag("li"); |
| | | List<DouBanStar> list = new ArrayList<>(); |
| | | for (int i = 0; i < items.size(); i++) { |
| | | Element item = items.get(i); |
| | | DouBanStar star = getStarInfo(item); |
| | | if (star != null) { |
| | | list.add(star); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | //获取电影的影人信息 |
| | | public static Celebrities getMovieStars(String movieId) throws IOException { |
| | | String url = String.format("https://movie.douban.com/subject/%s/celebrities", movieId); |
| | | Document doc = Jsoup.connect(url).timeout(60000).userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.81 Safari/537.36").get(); |
| | | |
| | | Elements eles = doc.getElementById("celebrities").getElementsByClass("list-wrapper"); |
| | | |
| | | Celebrities celebrities = new Celebrities(); |
| | | |
| | | for (int i = 0; i < eles.size(); i++) { |
| | | String type = eles.get(i).getElementsByTag("h2").get(0).ownText(); |
| | | if (type.contains("导演")) { |
| | | List<DouBanStar> list = getStarList(eles.get(i)); |
| | | celebrities.setDirectors(list); |
| | | } else if (type.contains("演员")) { |
| | | List<DouBanStar> list = getStarList(eles.get(i)); |
| | | celebrities.setStars(list); |
| | | } |
| | | } |
| | | return celebrities; |
| | | } |
| | | |
| | | |
| | | static class Celebrities { |
| | | |
| | | private List<DouBanStar> directors; |
| | | private List<DouBanStar> stars; |
| | | |
| | | public List<DouBanStar> getDirectors() { |
| | | return directors; |
| | | } |
| | | |
| | | public void setDirectors(List<DouBanStar> directors) { |
| | | this.directors = directors; |
| | | } |
| | | |
| | | public List<DouBanStar> getStars() { |
| | | return stars; |
| | | } |
| | | |
| | | public void setStars(List<DouBanStar> stars) { |
| | | this.stars = stars; |
| | | } |
| | | } |
| | | |
| | | |
| | | static class DouBanStar { |
| | | |
| | | private String id; |
| | | private String chineseName; |
| | | private String englishName; |
| | | private String avatar; |
| | | private String url; |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getChineseName() { |
| | | return chineseName; |
| | | } |
| | | |
| | | public void setChineseName(String chineseName) { |
| | | this.chineseName = chineseName; |
| | | } |
| | | |
| | | public String getEnglishName() { |
| | | return englishName; |
| | | } |
| | | |
| | | public void setEnglishName(String englishName) { |
| | | this.englishName = englishName; |
| | | } |
| | | |
| | | public String getAvatar() { |
| | | return avatar; |
| | | } |
| | | |
| | | public void setAvatar(String avatar) { |
| | | this.avatar = avatar; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) throws IOException { |
| | | getMovieStars("26309788"); |
| | | } |
| | | |
| | | } |