title: Scrape a jpg file on webpage, then saving it using python
body: <p>OK I'm trying to scrape jpg image from Gucci website. Take this one as example.</p>
  
  <p><a href="http://www.gucci.com/images/ecommerce/styles_new/201501/web_full/277520_F4CYG_4080_001_web_full_new_theme.jpg" rel="nofollow">http://www.gucci.com/images/ecommerce/styles_new/201501/web_full/277520_F4CYG_4080_001_web_full_new_theme.jpg</a></p>
  
  <p>I tried urllib.urlretrieve, which doesn't work becasue Gucci blocked the function. So I wanted to use requests to scrape the source code for the image and then write it into a .jpg file. </p>
  
  <pre><code>image = requests.get("http://www.gucci.com/images/ecommerce/styles_new/201501/web_full/277520_F4CYG_4080_001_web_full_new_theme.jpg").text.encode('utf-8')
  </code></pre>
  
  <p>I encoded it because if I don't, it keeps telling me that gbk cannot encode the string. </p>
  
  <p>Then:</p>
  
  <pre><code>with open('1.jpg', 'wb') as f:
      f.write(image)
  </code></pre>
  
  <p>looks good right? But the result is  -- the jpg file cannot be opened. There's no image! Windows tells me the jpg file is damaged. </p>
  
  <p>What could be the problem?</p>
  
  <ol>
  <li><p>I'm thinking that maybe when I scraped the image, I lost some information, or some characters are wrongly scraped. But how can I find out which?</p></li>
  <li><p>I'm thinking that maybe some information is lost via encoding. But if I don't encode, I cannot even print it, not to mention writing it into a file.</p></li>
  </ol>
  
  <p>What could go wrong?</p>