Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 2
    Many of the answers below are not a satisfactory replacement for wget. Among other things, wget (1) preserves timestamps (2) auto-determines filename from url, appending .1 (etc.) if the file already exists (3) has many other options, some of which you may have put in your .wgetrc. If you want any of those, you have to implement them yourself in Python, but it's simpler to just invoke wget from Python. Commented Sep 27, 2016 at 17:22
  • 3
    Short solution for Python 3: import urllib.request; s = urllib.request.urlopen('http://example.com/').read().decode()
    – Basj
    Commented Nov 26, 2019 at 9:47
  • wget is still a better approach, if you need to automatically retrieve filename and timestamps and handling duplicating files as stackoverflow.com/users/4958/shreevatsar stated. If the urls are variables, one can still handle in python using subprocess.
    – Tendai
    Commented Mar 2, 2023 at 8:19