title: Scraping images using beautiful soup
body: <p>I'm trying to scrape the image from an article using beautiful soup. It seems to work but I can't open the image. I get a file format error every time I try to access the image from my desktop. Any insights?</p>
  
  <pre><code>timestamp = time.asctime() 
  
  # Parse HTML of article, aka making soup
  soup = BeautifulSoup(urllib2.urlopen(url).read())
  
  # Create a new file to write content to
  txt = open('%s.jpg' % timestamp, "wb")
  
  # Scrape article main img
  links = soup.find('figure').find_all('img', src=True)
  for link in links:
      link = link["src"].split("src=")[-1]
      download_img = urllib2.urlopen(link)
      txt.write('\n' + "Image(s): " + download_img.read() + '\n' + '\n')
  
  txt.close()
  </code></pre>