0

please help me find the error as i didn’t understand for correctly :

from bs4 import BeautifulSoup
import requests
import pandas as pd
url = 'https://www.imdb.com/chart/top/?ref_=nv_mv_250'
response = requests.get(url)
with open("imdb_top_250_movies.html", mode='wb') as file:
    file.write(response.content)
soup = BeautifulSoup(response.content, 'lxml')
df_list = []
for movie in soup:
    title = movie.find('td' , class_="titleColumn").find('a').contents[0]
    year = movie.find('td' , class_="titleColumn").find('span').contents[0][1:-1]
    user_rating = movie.find('td' , class_="ratingColumn imdbRating").find('strong').contents[0]
    df_list.append({'title': title,
                    'year': int(year),
                    'user_ratings': float(user_rating)})
df = pd.DataFrame(df_list, columns = ['title', 'year', 'user_ratings'])
df

This is the error I got

TypeError Traceback (most recent call last) Input In [125], in <cell line: 8>() 9 soup = BeautifulSoup(response.content, 'lxml') 10 df_list = [] ---> 11 title = movie.find('td' , class_="titleColumn").find('a').contents[0] 12 year = soup.find('td' , class_="titleColumn").find('span').contents[0][1:-1] 13 user_rating = soup.find('td' , class_="ratingColumn imdbRating").find('strong').contents[0]

TypeError: find() takes no keyword arguments

Dodger
  • 1
  • 2

1 Answers1

0

Someone helped me with this answer as I wrote For incorrectly :

from bs4 import BeautifulSoup
import requests
import pandas as pd
url = 'https://www.imdb.com/chart/top'
response = requests.get(url)
with open("imdb_top_250_movies.html", mode='wb') as file:
    file.write(response.content)
soup = BeautifulSoup(response.content, 'lxml')
df_list = []
for movie in soup.find('tbody' , class_="lister-list").find_all('tr'):
    Place = movie.find('td' , class_="titleColumn").contents[0][1:-len('.\n      ')]
    title = movie.find('td' , class_="titleColumn").find('a').contents[0]
    year = movie.find('td' , class_="titleColumn").find('span').contents[0][1:-1]
    user_rating = movie.find('td' , class_="ratingColumn imdbRating").find('strong').contents[0]
    df_list.append({'place': Place,
                    'title': title,
                    'year': int(year),
                    'user_ratings': float(user_rating)})
df = pd.DataFrame(df_list, columns = ['place','title', 'year', 'user_ratings'])
df.style.hide(axis='index')
Dodger
  • 1
  • 2