How to download image from site with no clear extention?
<p>I am trying to download an image from the NGA.gov site using python 3 and urllib.</p>

<p>The site does not display images in a standard .jpg fashion and i get an error.</p>

<pre><code>import urllib.request
from bs4 import BeautifulSoup


try:
    with urllib.request.urlopen("http://images.nga.gov/?service=asset&amp;action=show_preview&amp;asset=33643") as url:
        s = url.read()

    soup = BeautifulSoup(s, 'html.parser') 


    img = soup.find("img")
    urllib.request.urlretrieve(img,"C:\art.jpg")

except Exception as e:
    print (e)
</code></pre>

<p>Error:
Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.
expected string or bytes-like object</p>

<p>Can someone please why i am getting this error and how to get the images to my computer. </p>

<p>There is no need to use BeautifulSoup! Just do:</p>

<pre><code>with urllib.request.urlopen("http://images.nga.gov/?service=asset&amp;action=show_preview&amp;asset=33643") as url:
    s = url.read()
with open("art.jpg", 'wb') as fp:
    fp.write(url.read())
</code></pre>

python web-scraping beautifulsoup