title: get image from website
body: <p>I try to improve a <a href="http://manual.calibre-ebook.com/news.html" rel="nofollow">recipe</a> for <a href="http://calibre-ebook.com/" rel="nofollow">calibre</a> and replace the default cover image with the cover image of the current newspaper issue.</p>
  
  <p>The way to go has something to do with <code>get_cover_url</code> (<a href="http://manual.calibre-ebook.com/news_recipe.html#calibre.web.feeds.news.BasicNewsRecipe.get_cover_url" rel="nofollow">link</a>).</p>
  
  <p>There are two problems:</p>
  
  <ol>
  <li>The URL of the cover image changes every day.</li>
  <li>I know virtually nothing about python.</li>
  </ol>
  
  <p>I hope for a solution like this (in pseudo-code):</p>
  
  <pre><code>OPEN URL "http://epaper.derstandarddigital.at/";
  coverElement = (SEARCH HTML-ELEMENT "&lt;img&gt;" WITH ID "imgPage2" AND CLASS "page");
  coverUrl = (GET HTML-ATTRIBUTE "src" FROM coverElement);
  RETURN coverUrl;
  </code></pre>
  
  <p>Would there be a way to achieve this in python*) (using only python standard libraries)?</p>
  
  <p>*) Calibre-Recipes seem to be python code</p>
  
  <p>[edit]
  here's the solution a friend of mine offered:</p>
  
  <pre><code>#!/usr/bin/env  python
  
  import urllib
  from time import strftime
  
  
  def get_cover_url(self):
      highResolution = True
  
      date    = strftime("%Y/%Y%m%d")
      # it is also possible for the past
      #date    = '2012/20120503'
  
      urlP1   = 'http://epaper.derstandarddigital.at/'
      urlP2   = 'data_ep/STAN/' + date
      urlP3   = '/V.B1/'
      urlP4   = 'paper.htm'
      urlHTML = urlP1 + urlP2 + urlP3 + urlP4
  
      htmlF  = urllib.urlopen(urlHTML)
      htmlC  = htmlF.read()
  
  
      # URL EXAMPLE: data_ep/STAN/2012/20120504/V.B1/pages/A3B6798F-2751-4D8D-A103-C5EF22F7ACBE.htm
      # consists of part2 + part3 + 'pages/' + code
      # 'pages/' has length 6, code has lenght 36
  
      index   = htmlC.find(urlP2) + len(urlP2 + urlP3) + 6 
      code    = htmlC[index:index + 36]
  
  
      # URL EXAMPLE HIGH RESOLUTION: http://epaper.derstandarddigital.at/data_ep/STAN/2012/20120504/pagejpg/A3B6798F-2751-4D8D-A103-C5EF22F7ACBE_b.png
      # URL EXAMPLE LOW RESOLUTION: http://epaper.derstandarddigital.at/data_ep/STAN/2012/20120504/pagejpg/2AB52F71-11C1-4859-9114-CDCD79BEFDCB.png
  
      urlPic  = urlP1 + urlP2 + '/pagejpg/' + code
  
      if highResolution:
          urlPic  = urlPic + '_b'
  
      urlPic  = urlPic + '.png'
  
      return urlPic
  
  
  
  if __name__ == '__main__':
      print get_cover_url(None)
  </code></pre>