How to get the image src data through beautifulsoup?
<p>I want to get the image src data of all <code>coming soon</code> movies from this link:-
<a href="http://www.fandango.com/moviescomingsoon?GenreFilter=Drama" rel="nofollow">Fandango.com</a> </p>

<p>This is the code:-</p>

<pre><code>def poster(genre):
      poster_link = []
      request = requests.get(http://www.fandango.com/moviescomingsoon?GenreFilter=genre)
      content = request.content
      soup = BeautifulSoup(content, "html.parser")
      soup2 = soup.find('div', {'class':'movie-ls-group'})
      elements = soup2.find_all('img')

      for element in elements:
          poster_link.append(element.get('src'))

      return poster_link
</code></pre>

<p>When I'm printing the poster_link array then it's giving me <code>None</code> instead of image source.</p>

<p>James's answer is great but I noticed it grabs more than the images for that particular section - it grabs the 'New + Coming Soon' section for the bottom of the page too, which seems to be outside the scope of the genre and appears on other pages. This code restricts the image grab to just the genre-specific coming soon section.</p>

<pre><code>def poster(genre):
    poster_link = []
    request = requests.get('http://www.fandango.com/moviescomingsoon?GenreFilter=' + genre)
    content = request.content
    soup = BeautifulSoup(content, "html.parser")
    comingsoon = soup.find_all('div', {'class':'movie-ls-group'})
    movies = comingsoon[0].find_all('img', {'class':'visual-thumb'})
    for movie in movies:
        poster_link.append(movie.get('data-src'))
    return poster_link

print (poster('Horror'))
</code></pre>

<p>You might also want to filter out the 'emptysource.jpg' images in your <code>poster_link</code> array before returning it, as they look like empty placeholders for movies without poster images.</p>

python beautifulsoup