name = BeautifulSoup(data.text, "html.parser") def director_analysis(soup): genres_movie = [] unique_genres = [] for lan in soup: genres_movie.append(lan["genres"]) # print(genres_movie) for i in genres_movie: if i not in unique_genres: # for k in i: if i not in unique_genres: unique_genres.append(i) # print(unique_genres) new_dict = {} for i in unique_genres: count = 1 for j in genres_movie: # for k in j: if i == j: count = count + 1 new_dict[i] = count data = open("saraltask11.json", "w") saral = json.dumps(new_dict, indent=4) data.write(saral) pprint(new_dict) director_analysis(scrape_movie_details(movie_function(name)))
"1970": [], "1980": [], "1990": [], "2000": [], "2010": [], "2020": [] } for i in task: if i["movie_year"] >= 1960 and i["movie_year"] <= 1969: dict_new["1960"].append(i) elif i["movie_year"] >= 1970 and i["movie_year"] <= 1979: dict_new["1970"].append(i) elif i["movie_year"] >= 1980 and i["movie_year"] <= 1989: dict_new["1980"].append(i) elif i["movie_year"] >= 1990 and i["movie_year"] <= 1999: dict_new["1990"].append(i) elif i["movie_year"] >= 2000 and i["movie_year"] <= 2010: dict_new["2000"].append(i) elif i["movie_year"] >= 2010 and i["movie_year"] <= 2019: dict_new["2010"].append(i) elif i["movie_year"] >= 2020 and i["movie_year"] <= 2030: dict_new["2020"].append(i) pprint(dict_new) data = open("saraltask3.json", "w") saral = json.dumps(dict_new, indent=4) data.write(saral) pprint(dict_new) scrape_top_list(movie_function(name))
data = requests.get(url) name = BeautifulSoup(data.text, "html.parser") def group_by_year(task): year = [] unique_year = [] new_list = [] for divs in name.find_all("span", class_='secondaryInfo'): years = int(divs.text[1:5]) year.append(years) for i in year: if i not in unique_year: unique_year.append(i) uniques_year = sorted(unique_year) print(uniques_year) newlist = [] for i in uniques_year: newdict = {} for j in task: if j["movie_year"] == i: newdict[i] = j newlist.append(newdict) pprint(newlist) data = open("saraltask2.json", "w") saral = json.dumps(newlist, indent=4) data.write(saral) group_by_year(movie_function(name))
data = requests.get(url) name = BeautifulSoup(data.text, "html.parser") def analyse_movies_language(soup): language_movie = [] unique_language = [] for lan in soup: language_movie.append(lan["movie_language"]) print(language_movie) for i in language_movie: for k in i: if k not in unique_language: unique_language.append(k) print(unique_language) new_dict = {} for i in unique_language: count = 1 for j in language_movie: for k in j: if i == k: count = count + 1 new_dict[i] = count data = open("saraltask6.json", "w") saral = json.dumps(new_dict, indent=4) data.write(saral) print(new_dict) analyse_movies_language(scrape_movie_details(movie_function(name)))
list_director=[] list_language=[] detail_movie["movie_name"]=i["movie_name"] names =soup1.find("div", class_="credit_summary_item") for name in names.find_all("a"): list_director.append(name.text) detail_movie["director"]=list_director for man in soup1.find_all("div", class_="txt-block"): for mans in man("a"): j=mans.get("href") if j=="/search/title?country_of_origin=in" : detail_movie["movie_country"]=mans.text elif "/search/title?title_type=feature&primary_language" in j: list_language.append(mans.text) detail_movie["movie_language"]=list_language for runtime in man.find_all("time"): detail_movie["runtime"]=runtime.text poster=soup1.find("div", class_="poster") for links in poster.find_all("img"): link=links.get("src") detail_movie["poster_img_url"]=link for genres in soup1.find_all("div", class_="see-more inline canwrap"): genres_movie=genres.find("a") detail_movie["genres"]=genres_movie.text list_movie.append(detail_movie) data=open("saraltaskch4.json","w") saral=json.dumps(list_movie, indent=4) data.write(saral) return list_movie print(scrape_movie_details(movie_function(name)))