How to print the full source code of URL? - in this particular case it prints only fractionFast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?NSXMLParserErrorDomain 111How To Get HTML source from URL with SwiftText gets truncated when converted from NSString to Swift StringFirebase storage image url not workingHow to know if a string is already escaped special with special characters?Cannot convert value of type '(User?, _) -> ()' to expected argument type.i am struggling to resolve that errorError handling for URLSession.shared.datataskLoading images from a URL and storing them locally using Swift4Cancelling a view controller from loading if a URL cannot load - Swift 4

Copying an existing HTML page and use it, is that against any copyright law?

Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?

Why did House of Representatives need to condemn Trumps Tweets?

What are the cons of stateless password generators?

Does Dispel Magic destroy Artificer Turrets?

What is more environmentally friendly? An A320 or a car?

If an arcane trickster rogue uses his mage hand and makes it invisible, does that mean anything the hand picks up is also invisible?

Incrementing add under condition in pandas

Why do they sell Cat 5 Ethernet splitters if you can’t split the signal?

Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?

Should I bike or drive to work? (6.8 mi)

Why does this RX-X lock not appear in Extended Events?

What is "sed -i 's,-m64,,g'" doing to this Makefile?

Why is it considered acid rain with pH <5.6?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

Golden Guardian removed before death related trigger

Does dual boot harm a laptop battery or reduce its life?

Dual-national, returning to US the day the US Passport expires; can he check in with airline on Dutch passport but reenter with expiring US passport?

If Trump gets impeached, how long would Pence be president?

Is there an antonym for "spicy" or "hot" regarding food?

Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?

What language is Raven using for her attack in the new 52?

Dobbs Murder Mystery : A Picture worth 1000 words?

Is it okay for me to decline a project on ethical grounds?



How to print the full source code of URL? - in this particular case it prints only fraction


Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?NSXMLParserErrorDomain 111How To Get HTML source from URL with SwiftText gets truncated when converted from NSString to Swift StringFirebase storage image url not workingHow to know if a string is already escaped special with special characters?Cannot convert value of type '(User?, _) -> ()' to expected argument type.i am struggling to resolve that errorError handling for URLSession.shared.datataskLoading images from a URL and storing them locally using Swift4Cancelling a view controller from loading if a URL cannot load - Swift 4






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I have already retrieved source codes from some sites for my app and have used the function:



let usedURLString = "my http link"



guard let usedURL = URL(string: usedURLString) else
// if URL is not valid:
print("Error: (usedURLString) doesn't seem to be a valid URL")
return
do
// getting the HTML sourcecode

let sourceCodeHTML = try String(contentsOf: usedURL, encoding: String.Encoding.windowsCP1254)

print(sourceCodeHTML)
catch
print("there was an error: (error)")



Now I am struggling with the problem that I can't retrieve the full source code from a site that says it needs "This page needs javascript to run". When using the function above it prints only a small and weird fraction of html string. Can anyone help me with the issue? I have searched in many places but haven't found any solution to the issue.










share|improve this question



















  • 4





    Well, for one thing, String(contentsOf: usedURL) is absolutely not the correct way to fetch the HTML from a web page. You are networking, use URLSession. That's what it's for.

    – matt
    Mar 26 at 19:48











  • Could you please provide the link from which you want to retrieve the source code? I delete encoding: String.Encoding.windowsCP1254 and it works for me to retrieve something. Maybe you could change the String.Encoding type.

    – Yaming Lin
    Mar 26 at 20:09












  • I have already tried changing the encoding type with no success. here is the link: olx.pl/nieruchomosci/mieszkania/sprzedaz/…

    – Timothy Stokarski
    Mar 26 at 21:00












  • I tried your code and it works well for me. I did get the source HTML code. Could you please show your error message?

    – Yaming Lin
    Mar 27 at 1:57











  • There is no error, yet although the console prints source HTML code it is only a fraction of it. If I open source code via chrome on my computer it shows the full, very long code that I need. That is the whole issue

    – Timothy Stokarski
    Mar 27 at 9:26

















-1















I have already retrieved source codes from some sites for my app and have used the function:



let usedURLString = "my http link"



guard let usedURL = URL(string: usedURLString) else
// if URL is not valid:
print("Error: (usedURLString) doesn't seem to be a valid URL")
return
do
// getting the HTML sourcecode

let sourceCodeHTML = try String(contentsOf: usedURL, encoding: String.Encoding.windowsCP1254)

print(sourceCodeHTML)
catch
print("there was an error: (error)")



Now I am struggling with the problem that I can't retrieve the full source code from a site that says it needs "This page needs javascript to run". When using the function above it prints only a small and weird fraction of html string. Can anyone help me with the issue? I have searched in many places but haven't found any solution to the issue.










share|improve this question



















  • 4





    Well, for one thing, String(contentsOf: usedURL) is absolutely not the correct way to fetch the HTML from a web page. You are networking, use URLSession. That's what it's for.

    – matt
    Mar 26 at 19:48











  • Could you please provide the link from which you want to retrieve the source code? I delete encoding: String.Encoding.windowsCP1254 and it works for me to retrieve something. Maybe you could change the String.Encoding type.

    – Yaming Lin
    Mar 26 at 20:09












  • I have already tried changing the encoding type with no success. here is the link: olx.pl/nieruchomosci/mieszkania/sprzedaz/…

    – Timothy Stokarski
    Mar 26 at 21:00












  • I tried your code and it works well for me. I did get the source HTML code. Could you please show your error message?

    – Yaming Lin
    Mar 27 at 1:57











  • There is no error, yet although the console prints source HTML code it is only a fraction of it. If I open source code via chrome on my computer it shows the full, very long code that I need. That is the whole issue

    – Timothy Stokarski
    Mar 27 at 9:26













-1












-1








-1








I have already retrieved source codes from some sites for my app and have used the function:



let usedURLString = "my http link"



guard let usedURL = URL(string: usedURLString) else
// if URL is not valid:
print("Error: (usedURLString) doesn't seem to be a valid URL")
return
do
// getting the HTML sourcecode

let sourceCodeHTML = try String(contentsOf: usedURL, encoding: String.Encoding.windowsCP1254)

print(sourceCodeHTML)
catch
print("there was an error: (error)")



Now I am struggling with the problem that I can't retrieve the full source code from a site that says it needs "This page needs javascript to run". When using the function above it prints only a small and weird fraction of html string. Can anyone help me with the issue? I have searched in many places but haven't found any solution to the issue.










share|improve this question














I have already retrieved source codes from some sites for my app and have used the function:



let usedURLString = "my http link"



guard let usedURL = URL(string: usedURLString) else
// if URL is not valid:
print("Error: (usedURLString) doesn't seem to be a valid URL")
return
do
// getting the HTML sourcecode

let sourceCodeHTML = try String(contentsOf: usedURL, encoding: String.Encoding.windowsCP1254)

print(sourceCodeHTML)
catch
print("there was an error: (error)")



Now I am struggling with the problem that I can't retrieve the full source code from a site that says it needs "This page needs javascript to run". When using the function above it prints only a small and weird fraction of html string. Can anyone help me with the issue? I have searched in many places but haven't found any solution to the issue.







ios swift






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 19:44









Timothy StokarskiTimothy Stokarski

1




1










  • 4





    Well, for one thing, String(contentsOf: usedURL) is absolutely not the correct way to fetch the HTML from a web page. You are networking, use URLSession. That's what it's for.

    – matt
    Mar 26 at 19:48











  • Could you please provide the link from which you want to retrieve the source code? I delete encoding: String.Encoding.windowsCP1254 and it works for me to retrieve something. Maybe you could change the String.Encoding type.

    – Yaming Lin
    Mar 26 at 20:09












  • I have already tried changing the encoding type with no success. here is the link: olx.pl/nieruchomosci/mieszkania/sprzedaz/…

    – Timothy Stokarski
    Mar 26 at 21:00












  • I tried your code and it works well for me. I did get the source HTML code. Could you please show your error message?

    – Yaming Lin
    Mar 27 at 1:57











  • There is no error, yet although the console prints source HTML code it is only a fraction of it. If I open source code via chrome on my computer it shows the full, very long code that I need. That is the whole issue

    – Timothy Stokarski
    Mar 27 at 9:26












  • 4





    Well, for one thing, String(contentsOf: usedURL) is absolutely not the correct way to fetch the HTML from a web page. You are networking, use URLSession. That's what it's for.

    – matt
    Mar 26 at 19:48











  • Could you please provide the link from which you want to retrieve the source code? I delete encoding: String.Encoding.windowsCP1254 and it works for me to retrieve something. Maybe you could change the String.Encoding type.

    – Yaming Lin
    Mar 26 at 20:09












  • I have already tried changing the encoding type with no success. here is the link: olx.pl/nieruchomosci/mieszkania/sprzedaz/…

    – Timothy Stokarski
    Mar 26 at 21:00












  • I tried your code and it works well for me. I did get the source HTML code. Could you please show your error message?

    – Yaming Lin
    Mar 27 at 1:57











  • There is no error, yet although the console prints source HTML code it is only a fraction of it. If I open source code via chrome on my computer it shows the full, very long code that I need. That is the whole issue

    – Timothy Stokarski
    Mar 27 at 9:26







4




4





Well, for one thing, String(contentsOf: usedURL) is absolutely not the correct way to fetch the HTML from a web page. You are networking, use URLSession. That's what it's for.

– matt
Mar 26 at 19:48





Well, for one thing, String(contentsOf: usedURL) is absolutely not the correct way to fetch the HTML from a web page. You are networking, use URLSession. That's what it's for.

– matt
Mar 26 at 19:48













Could you please provide the link from which you want to retrieve the source code? I delete encoding: String.Encoding.windowsCP1254 and it works for me to retrieve something. Maybe you could change the String.Encoding type.

– Yaming Lin
Mar 26 at 20:09






Could you please provide the link from which you want to retrieve the source code? I delete encoding: String.Encoding.windowsCP1254 and it works for me to retrieve something. Maybe you could change the String.Encoding type.

– Yaming Lin
Mar 26 at 20:09














I have already tried changing the encoding type with no success. here is the link: olx.pl/nieruchomosci/mieszkania/sprzedaz/…

– Timothy Stokarski
Mar 26 at 21:00






I have already tried changing the encoding type with no success. here is the link: olx.pl/nieruchomosci/mieszkania/sprzedaz/…

– Timothy Stokarski
Mar 26 at 21:00














I tried your code and it works well for me. I did get the source HTML code. Could you please show your error message?

– Yaming Lin
Mar 27 at 1:57





I tried your code and it works well for me. I did get the source HTML code. Could you please show your error message?

– Yaming Lin
Mar 27 at 1:57













There is no error, yet although the console prints source HTML code it is only a fraction of it. If I open source code via chrome on my computer it shows the full, very long code that I need. That is the whole issue

– Timothy Stokarski
Mar 27 at 9:26





There is no error, yet although the console prints source HTML code it is only a fraction of it. If I open source code via chrome on my computer it shows the full, very long code that I need. That is the whole issue

– Timothy Stokarski
Mar 27 at 9:26












1 Answer
1






active

oldest

votes


















0














Try this:



let usedURLString = "my http link"
if let url = URL(string: usedURLString)
do
let contents = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
print(contents)
catch
// contents could not be loaded

else
// the URL was bad!






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365150%2fhow-to-print-the-full-source-code-of-url-in-this-particular-case-it-prints-on%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try this:



    let usedURLString = "my http link"
    if let url = URL(string: usedURLString)
    do
    let contents = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
    print(contents)
    catch
    // contents could not be loaded

    else
    // the URL was bad!






    share|improve this answer





























      0














      Try this:



      let usedURLString = "my http link"
      if let url = URL(string: usedURLString)
      do
      let contents = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
      print(contents)
      catch
      // contents could not be loaded

      else
      // the URL was bad!






      share|improve this answer



























        0












        0








        0







        Try this:



        let usedURLString = "my http link"
        if let url = URL(string: usedURLString)
        do
        let contents = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
        print(contents)
        catch
        // contents could not be loaded

        else
        // the URL was bad!






        share|improve this answer













        Try this:



        let usedURLString = "my http link"
        if let url = URL(string: usedURLString)
        do
        let contents = try String(contentsOfURL: myURL, encoding: NSUTF8StringEncoding)
        print(contents)
        catch
        // contents could not be loaded

        else
        // the URL was bad!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 20:03









        Joshua CleetusJoshua Cleetus

        1861 silver badge9 bronze badges




        1861 silver badge9 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365150%2fhow-to-print-the-full-source-code-of-url-in-this-particular-case-it-prints-on%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript