0

Hi I am trying to web scrape the following page:

https://www.imdb.com/chart/top

I want to grab all the director names that show when you hover over any movie name:

here is what I did:

direc = requests.get(imdb).content
direc_b = BeautifulSoup(direc, 'lxml')
direc_b_t = direc_b.find_all(class_= "titleColumn")

the result i am getting is the following:

<td class="titleColumn">
       1.
       <a href="/title/tt0111161/" title="Frank Darabont (dir.), Tim Robbins, Morgan Freeman">Die Verurteilten</a>
 <span class="secondaryInfo">(1994)</span>
 </td> 

what I want to grab is the following line but I am not sure what I should do next.:

title="Frank Darabont (dir.), Tim Robbins, Morgan Freeman 

Any idea?

Thanks

Samsul Islam
  • 2,581
  • 2
  • 17
  • 23
  • Does this answer your question? [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) – JaSON Dec 10 '20 at 16:57
  • Loop through the list in `direc_b_t` and for each item in the list, `print(item.find('a')['title'])` –  Dec 10 '20 at 17:01

1 Answers1

0

This should work

import requests
from bs4 import BeautifulSoup

request = requests.get("https://www.imdb.com/chart/top")
soup = BeautifulSoup(request.content, "html.parser")

for td in soup.findAll('td', {'class': 'titleColumn'}):
    for each in td.findAll('a'):
        director = each.get('title')
        print(director)
sal
  • 74
  • 7