title: Downloading a file with a URL using python
body: <p>I want to download the file in the following url using python. I tried with the following code but it seems like not working. I think the error is in the file format. I would be glad if you can suggest the modifications to the code or a new code that I can use for this purpose</p>
  <p>Link to the website</p>
  <p><a href="https://www.gov.uk/government/statistics/transport-use-during-the-coronavirus-covid-19-pandemic" rel="nofollow noreferrer">https://www.gov.uk/government/statistics/transport-use-during-the-coronavirus-covid-19-pandemic</a></p>
  <p>URL required to be downloaded</p>
  <p><a href="https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/959864/COVID-19-transport-use-statistics.ods" rel="nofollow noreferrer">https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/959864/COVID-19-transport-use-statistics.ods</a></p>
  <p>My Code</p>
  <pre><code>from urllib import request
  
  
  response = request.urlopen(&quot;https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/959864/COVID-19-transport-use-statistics.ods&quot;)
  csv = response.read()
  
  
  csvstr = str(csv).strip(&quot;b'&quot;)
  
  lines = csvstr.split(&quot;\\n&quot;)
  f = open(&quot;historical.csv&quot;, &quot;w&quot;)
  for line in lines:
     f.write(line + &quot;\n&quot;)
  f.close()
  </code></pre>
  <p>Here basically I only want to download the file. I have heard that Beautifulsoup can be used for that but I don't have much experience on this. Any code that would serve my purpose is highly appreciated</p>
  <p>Thanks</p>