Change language

Emotion-based movie recommendations in Python

| |

Install BeautifulSoup and lxml ,
Open terminal and write

 pip install beautifulsoup4 pip install lxml 

The scraper is written in Python and uses lxml to parse web pages. BeautifulSoup is used to extract data from HTML and XML files.

Film-related emotions

There are 8 classes of emotions that would be efficient for classifying text ... These are: Anger, Expectation, Disgust, Fear, Joy, Sad, Surprise, Trust . Here they are taken as input and the corresponding movies will be displayed for emotion. 
The correspondence of each emotion to the genre of cinema is listed below:

Garden — Drama
Disgust — Musical
Anger — Family
Waiting — Thriller
Fear — Sports
Enjoyment — Thriller
Trust — Western
Surprise — Film Noir

Based on emotions, the appropriate genre will be selected, and all 5 best films of this genre will be recommended to the user.

# Python3 movie code
# recommendation based
# emotion

 
# Import web library
# scrapped

from bs4 import BeautifulSoup as SOUP

import re

import requests as HTTP

 
# Main function for scraping  

def main (emotion):

 

  # IMDb URL for the drama genre

# film against emotions Garden

if (emotion = = "Sad" ):

urlhere = http://www.imdb.com/search/title?genres=drama& title_type = feature & amp; sort = moviemeter , asc’

  

# IMDb URL for music genre

# film against emotions Disgust

elif (emotion = = "Disgust" ):

urlhere = http://www.imdb.com/search/title?genres=musical&title_type=feature&sort = moviemeter , asc’

 

# IMDb URL for Family genre

# film against emotions Anger

  elif (emotion = = " Anger " ):

  urlhere = http://www.imdb.com/search/title?genres = family & amp; title_type = feature & amp; sort = moviemeter , asc’

 

# IMDb URL for thriller genre

# film against emotions

  elif (emotion = = "Anticipation" ):

urlhere = http://www.imdb.com/search/title ? genres = thriller & amp; title_type = feature & amp; sort = moviemeter , asc’

 

# IMDb Url for Sport genre

  # film against fear emotions

elif (emotion =   = "Fear" ):

urlhere = http://www.imdb.com/ search / title? genres = sport & amp; title_type = feature & amp; sort = moviemeter , asc’

 

# IMDb URL for genre thriller

# film against emotions

elif (emotion = = "Enjoyment" ):

  urlhere = http://www.imdb.com/search/title?genres = thriller & amp; title_type = feature & amp; sort = moviemeter , asc’

 

# IMDb URL for Western genre

# film against emotions of trust

elif (emotion = = "Trust" ):

urlhere = http://www.imdb.com/search/title?genres= western & amp; title_type = feature & amp; sort = moviemeter , asc’

 

# IMDb URL for Film_noir genre

# film against emotions surprise

elif (emotion = = "Surprise" ):

urlhere = http://www.imdb.com/search/title?genres=film_noir&title_type=feature&sort=moviemeter , asc’

 

# HTTP request to get data

# whole page

response = HTTP.get (urlhere)

data = response.text

 

  # Parse data with

# BeautifulSoup

soup = SOUP (data, "lxml" )

 

# Extract movie titles from

  # data using regular expressions

title = soup.find_all ( "a" , attrs = { "href" : re. compile (r ’/ title / tt + d * /’ )})

return title

 
# Driver function

if __ name__ = = ’ __main__’ :

 

emotion = input ( "Enter the emotion:" )

a = main (emotion)

count = 0

 

if (emotion = = "Disgust" or emotion = = "Anger"

or emotion = = "Surprise" ):

  

for i in a:

 

# Separate each line

# IMDb data for To clean up movies

tmp = str (i) .split ( ’& gt ;;’ )

 

if ( len (tmp) = = 3 ):

print (tmp [ 1 ] [: - 3 ])

 

if (count"  13 ):

  break

count + = 1

else :

  for i in a :

tmp = str (i) .split ( ’& gt;’ )

 

  if ( len (tmp) = = 3 ):

print (tmp [ 1 ] [: - 3 ])

 

if (count"  11 ):

  break

count + = 1

This script will scrape all movie titles in the genre corresponding to the entered emotion and make a list for the user.

Web Scraping is very useful for extracting data and analyzing it. Without Web Cleaning, the Internet, as you know, would not really exist. This is because Google and other major search engines use a sophisticated web scraper to extract content to be included in their index. These tools make search engines possible.

Application crawling

  • Article retrieval for sites that curate content.
  • Business list retrieval for companies that create databases of leads.
  • Many different types of data extraction, sometimes referred to as data extraction. For example, one of the popular and sometimes controversial uses of the web scraper — This is a reduction in airline prices for publication on airfare comparison sites.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method