Python Programming Tutorial – 24 – Downloading Files from the Web

Home/Programming Video Tutorials/Python Video Tutorials/Python Programming Tutorial – 24 – Downloading Files from the Web

Python Programming Tutorial – 24 – Downloading Files from the Web

FavoriteLoadingAdd to favorites

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

By | 2017-06-13T02:11:50+00:00 June 13th, 2017|Python Video Tutorials|49 Comments

49 Comments

  1. Dustin Knudsen June 13, 2017 at 2:13 am - Reply

    This didn’t work for me. I went over and over and tried different methods and ways of importing, made sure there were no errors. PyCharm processed it with no errors or objections. But nothing popped up. No new file, nothing. I don’t know why.

  2. Mohamed Khaled June 13, 2017 at 2:15 am - Reply

    is "import urllib.request" the same as "from urllib import request" ?

  3. Roger Tunnell June 13, 2017 at 2:16 am - Reply

    When I tried this it wouldn’t work with any .csv urls from yahoo finance. It worked (minus appropriate line breaks) with .csv urls from another source though. Is there some mechanism that yahoo is using now to block this sort of thing that didn’t exist when the video was created?

  4. Agitating Skeleton June 13, 2017 at 2:17 am - Reply

    You can no longer download data from Yahoo this way, so you’ll have to find a .csv file from somewhere else. Not very difficult, but just a heads up.

  5. meghal darji June 13, 2017 at 2:18 am - Reply

    I am using pycharm professional version, on running the above code I get an error message which says:
    Fatal Python error: Py_Initialize: unable to load the file system codec
    ImportError: No module named ‘encodings’

    Current thread 0x00000e88 (most recent call first):
    what should i do?

  6. FsimulatorX June 13, 2017 at 2:18 am - Reply

    This tutorial caused a memory leak in my brain

  7. Kin Cheng June 13, 2017 at 2:19 am - Reply
  8. shubham sharma June 13, 2017 at 2:22 am - Reply

    For folks using python 2:
    replace first line with import urllib2
    and use:response=urllib2.urlopen(csv_url)

  9. Popart 2015 June 13, 2017 at 2:25 am - Reply

    10:27 Why the "b" character at the beginning? Should have started with "Date" right away…!

  10. PapiDimmi June 13, 2017 at 2:26 am - Reply

    Why do you not use an adblocker?

  11. allen john June 13, 2017 at 2:26 am - Reply

    what does "dest_url = r’goog.csv’" do here? and also when i’m running the same code filename dest_url is being created instead of goog.csv.why is that so?

  12. Akash Singh June 13, 2017 at 2:26 am - Reply

    Just got lost.

  13. RagHelen June 13, 2017 at 2:27 am - Reply

    I really wonder what is going inside a brain which uses this screen size for a video tutorial.

  14. Hitarth Panchal June 13, 2017 at 2:28 am - Reply

    getting an error in this statement
    response = request.urlopen(csv_url)

  15. Our Tech Life June 13, 2017 at 2:28 am - Reply

    when you used the split() method, the parameter you put in was ‘\n’ why 2 backlashes??? New to coding lol

  16. Phil Kroche June 13, 2017 at 2:29 am - Reply

    Pretty messy code. Functions are not supposed to have more than 3-4 lines of code. Split up your function

  17. Ramesh Ashok June 13, 2017 at 2:29 am - Reply

    line = csv_str.split("\n")
    In this line, why there are two backslashes?

  18. Boody Ahmed June 13, 2017 at 2:29 am - Reply

    Guys when i wrote from urllib import (request) python told me that is not defined " unresolved reference " what should i do ?

  19. TNTSquid June 13, 2017 at 2:31 am - Reply

    can i ask why not csv = str(response.read())?

  20. Daniel Matthews June 13, 2017 at 2:31 am - Reply

    I get this error :
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 401: Unauthorized

  21. Ruturaj Vaidya June 13, 2017 at 2:34 am - Reply

    In case u r using a lower version of python use – import urllib and then in the function –
    response = urllib.urlopen(url)

  22. Burak Yildirim June 13, 2017 at 2:34 am - Reply

    hey bucky i appreciate your works, but i wish you would explain more about how ‘request.urlopen’ and ‘.split()’ functions work

  23. Abid Riaz June 13, 2017 at 2:35 am - Reply

    I was writing along but I guess I got lost when you stored the file and then wrote and read into it. I know most of the actions you took but never seen them used all together. I will come back to this video when done with the series.

  24. Ran Xiao June 13, 2017 at 2:35 am - Reply

    Well explained! just one question, who was it at the door?

  25. Damien Bertrand June 13, 2017 at 2:37 am - Reply

    any reason why my csv file only contains 25 lines of data?

  26. Hugues Soares June 13, 2017 at 2:39 am - Reply

    .split(”\n”) –> the string became one big list with only one really big element!! Best way to see that is to test it 🙂

    Hugues Soares

  27. Celtic Tiger June 13, 2017 at 2:39 am - Reply

    Thanks works for me on 27/04/17

  28. Shawn White June 13, 2017 at 2:42 am - Reply

    went from 0-100 real quick

  29. jaevulen June 13, 2017 at 2:43 am - Reply

    would it be possible to just type "import urllib" in the beginning and then type "urllib.urlopen(csv_url)" instead of "request.urlopen(csv_url)"?

  30. aravind R June 13, 2017 at 2:44 am - Reply

    Brother while closing the file it shows indentation error i don’t know can you help me bukky!!!!!!!!!!

  31. Sidali SMAILI June 13, 2017 at 2:46 am - Reply

    when i did it i feel like awwwwwwwwwwwwsome :p thnx

  32. Manzar Imam June 13, 2017 at 2:48 am - Reply

    Traceback (most recent call last):
    File "down.py", line 15, in <module>
    download_csv(goog_url)
    File "down.py", line 6, in download_csv
    response=response.urlopen(url)
    UnboundLocalError: local variable ‘response’ referenced before assignment

    I’am getting this error can anyone help?

  33. Abid Riaz June 13, 2017 at 2:51 am - Reply

    You didn’t answer how "\n" break up everything by character? How does it know to break up by, say, every ten characters or 15 characters or any number of characters? You asked the question but then talked about someone being at the door 🙂

  34. chibuzor agubulom June 13, 2017 at 2:51 am - Reply

    how does python know it is suppose to create a separate file with name goog.csv

  35. Atul Singh June 13, 2017 at 2:52 am - Reply

    from urllib import request
    ImportError: cannot import name request

    which type of error it is???

  36. karthik puvvula June 13, 2017 at 2:52 am - Reply

    this is where it gets interesting !! thank you 🙂

  37. Алекс June 13, 2017 at 2:54 am - Reply

    nowtime google price is 806 000 000 000; +41% in 2,4 year :O

  38. Deniz Kendirci June 13, 2017 at 2:55 am - Reply

    it’s all nice and good, but how do we remember the library names, module names, function names.

    assuming someone, who has just started to learn like us, wants to write some code on a specific purpose, how can he recall the module names that’s the most suitable ones for his purpose? will it take lots and lots of iterations and repetitions of practice or are there some algoritmic and methodical thinking, tips and tricks behind it?

  39. Erggo the Magnificent June 13, 2017 at 2:57 am - Reply

    Using Python 2.7.13,

    It doesn’t like this: from urllib import request
    Or this: response = request.urlopen(csv_url)

    Instead type this: import urllib
    And this: reponse = urllib.urlopen(csv_url)

    Works for me. Thanks for the tutorial.

  40. sujaysukumar123 June 13, 2017 at 2:57 am - Reply

    Please help: The downloaded csv file had all its contents enclosed in b’….<csv data> …’
    why is that? how can I remove that?

  41. Mozer June 13, 2017 at 2:58 am - Reply

    How do i download a web file

  42. Shashwat Khanna June 13, 2017 at 2:59 am - Reply

    1:17 check the user account. Bucky isn’t his real name.

  43. Crimx June 13, 2017 at 3:00 am - Reply

    The only issue i am running into is that i am using the older version of python :/ so my import urlibb isn’t working

  44. Gazi Muhib June 13, 2017 at 3:01 am - Reply

    only csv file can read?

  45. Adam -亚当- June 13, 2017 at 3:01 am - Reply

    Yahoo masks their link URL now, so it wont work 🙁

  46. joshua ganzon June 13, 2017 at 3:03 am - Reply

    im sorry but the program didnt work I tried so many times and it printed this:

    File "C:/Users/joshua/PycharmProjects/untitled4/python.py", line 3
    goog_url = http://chart.finance.yahoo.com/table.csv?s=GOOG&a=11&b=1&c=2016&d=11&e=31&f=2016&g=d&ignore=.csv
    ^
    SyntaxError: invalid syntax

  47. Lamcis Fark June 13, 2017 at 3:06 am - Reply

    The important part is 10:28 – 10:33

    btw nice "Informateon" Bucky

  48. SriKanth Komma June 13, 2017 at 3:09 am - Reply

    Glad for teaching me this with the stock stuff.

  49. Clarke West June 13, 2017 at 3:10 am - Reply

    Can we use a similar process for downloading images as well?

Leave A Comment

*