title: How to extract all the hrefs and src inside specific divs with beautifulsoup python
body: <p>I want to extract all the href and src inside all the divs on the page that have class = 'news_item' </p>
  
  <p>The html looks like this:</p>
  
  <pre><code>&lt;div class="col"&gt;
  &lt;div class="group"&gt;
  &lt;h4&gt;News&lt;/h4&gt;
  &lt;div class="news_item"&gt;
  
  &lt;a href="www.link.com"&gt;
  
  &lt;h2 class="link"&gt;
  here is a link-heading
  &lt;/h2&gt;
  &lt;div class="Img"&gt;
  &lt;img border="0" src="/image/link" /&gt;
  &lt;/div&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>from here what I want to extract is:</p>
  
  <p><strong>www.link.com , here is the link-heading and /image/link</strong></p>
  
  <p>My code is:</p>
  
  <pre><code> def scrape_a(url):
  
          news_links = soup.select("div.news_item [href]")
          for links in news_links:
            if news_links:
              return 'http://www.web.com' + news_links['href']
  
      def scrape_headings(url):
          for news_headings in soup.select("h2.link"):
            return str(news_headings.string.strip())
  
  
      def scrape_images(url):
          images = soup.select("div.Img[src]")
          for image in images:
            if images:
              return 'http://www.web.com' + news_links['src']
  
  
      def top_stories():
  
  
      r = requests.get(url)
    soup = BeautifulSoup(r.content)
    link = scrape_a(soup)
    heading = scrape_headings(soup)
    image = scrape_images(soup)
    message = {'heading': heading, 'link': link, 'image': image}
    print message
  </code></pre>
  
  <p>The problem is that it gives me error:</p>
  
  <pre><code>    **TypeError: 'NoneType' object is not callable**
  </code></pre>
  
  <p>Here is the Traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "web_parser.py", line 40, in &lt;module&gt;
      top_stories()
    File "web_parser.py", line 32, in top_stories
      link = scrape_a('www.link.com')
    File "web_parser.py", line 10, in scrape_a
      news_links = soup.select_all("div.news_item [href]")
  </code></pre>