what is the best way to download webpage?

Discussion in 'Mac Programming' started by saleh.hi.62, Nov 12, 2011.

  1. saleh.hi.62 macrumors member

    Joined:
    Jul 25, 2011
    #1
    hello guys,

    I have a NSArray of webpages' URLs , what is the best way to download all the links? every 5 sec i need to download all the links which are inside the array.

    NSUrl? any better way?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    There is a section of the NSString documentation:
    Creating and Initializing a String from an URL

    There are many options for you to choose from to get an NSString containing the contents of a webpage given its URL.

    -Lee
     
  3. saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #3
    thanks bro, but what i am going to do is to download webpage!

    NSURLConnection is a good choice?
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    I provided you with what I think are the best methods for achieving your goal. Did you try them and they were insufficient for your purposes? If so, what did happen and what were you hoping for?

    -Lee
     
  5. saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #5
    as what i have mentioned again, i am not trying to fetch the content of webpage! i am trying to download the webpage on local machine.
     
  6. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    So I gave you information on how to get the contents stored at a particular URL into a string. You want those contents stored in a file. What would the next step be?
    http://developer.apple.com/library/...String/writeToFile:atomically:encoding:error:

    If I was doing this particular task, I'd be writing a shell script that used wget or curl depending on availability, but if you're going "heavy-weight" and using Objective-C, I'd use the NSString methods above because they're what I know. There may well be a single method elsewhere that will do this in one step.

    -Lee
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    Read the URL Loading System Programming Guide. There's a link to it in the left-side "Table of Contents" column of the NSURLConnection class reference doc.

    Pay particular attention to the classes NSURLConnection and NSURLDownload.
     
  8. saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #8
    is there anyone who can show me an example how to download a webpage into a folder using NSURLConnection?
     
  9. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #9
    Why use NSURLConnection and not NSURLDownload?

    Isn't that what you want?


    The NSURLDownload chapter of the URL Loading System Programming Guide that chown33 kindly pointered you towards has lots of examples of using NSURLDownload with lots of detailed explanation.
     
  10. saleh.hi.62, Nov 13, 2011
    Last edited: Nov 13, 2011

    saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #10
    because my application gonna be baseed on IOS! NSURLDownload does not work on IOS.
     
  11. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #11
    1) you didn't say iOS, which meant everyone thought you were using OS X, because:
    2) you're posting in the wrong forum. Go to the iOS programming forum for iOS-specific questions.

    Acting exasperated that we don't know a detail of your question you didn't mention serves only to frustrate those that might help you here and on the iOS forum. Be specific with your questions, it will benefit everyone.

    -Lee
     
  12. saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #13
    i think you are facing that issue so much emotional ! NSURLConnection works on MAC OSX and IOS, so i does not matter i ask this question here or in iphone forum!

    what i need to know is how to download a webpage using NSURLConnection, thats all :)
     
  13. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #14
  14. saleh.hi.62, Nov 13, 2011
    Last edited: Nov 13, 2011

    saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #15
    yes i searched, but there was no sample for that! were you able to find one?
    yes i tried, for NSURLDownload there is a clear and helpful documentation that exactly helps you for this matter, but for NSURLConection its not that easy to find how it works!
     

Share This Page