title: How to know download file extension in python?
body: <p>This is my jpg image download source:</p>
  <pre><code>from bs4 import BeautifulSoup
  import requests
  from selenium import webdriver
  import urllib.request
  import os
  import shutil
  from mimetypes import guess_extension
  
  img_folder = (&quot;c:/test&quot;)
  if os.path.exists(img_folder):
      shutil.rmtree(img_folder)
  
  path = (r&quot;C:\Users\qpslt\Desktop\py\chromedriver_win32\chromedriver.exe&quot;)
  driver = webdriver.Chrome(path)
  site_url = (&quot;https://gall.dcinside.com/board/view/?id=baseball_new8&amp;no=10131338&amp;exception_mode=recommend&amp;page=1&quot;)
  driver.get(site_url)
  images = driver.find_elements_by_xpath('//div[@class=&quot;writing_view_box&quot;]//img')
  
  for i, img in enumerate(images, 1):
      img_url = img.get_attribute('src')
      print(i, img_url)
      r = requests.get(img_url, headers={'Referer': site_url})
      try:   #폴더 만들기
          if not os.path.exists(img_folder):
              os.makedirs(img_folder)
      except Exception as er:
          print(&quot;{}에러가 발생했습니다.&quot;.format(er))
          break;
      break;
      with open(&quot;c:/test/{}.jpg&quot;.format(i), 'wb') as f:
          f.write(r.content)
  </code></pre>
  <p>I don't always know the extension of the image.</p>
  <p>How do you know the extension of the file you are downloading?</p>