How to get HTML Source from URL in Swift Anonymously?












0















I am trying to scrape html code from a URL using Swift, but it needs to be done anonymously.
The issue with my case is that the content differs when I am logged in the website or not. My app has a webkit that allows users to view a certain page of a website. If they log in via the webkit, the scraping result is different from if they did not log in.



I have read and searched through tons of questions on StackOverflow to see how to get the HTML source from a URL and the one that I am using can be found here:
How To Get HTML source from URL with Swift I have also tried the codes from different answers and questions.



guard let getHTMLString = try? String(contentsOf: theUrl, encoding: .utf8).condensingWhitespace() as String else {
callErrorPage()
return
}


I get the content of the html page with the code above.



But like I mentioned above, the codes differ if the user has logged in the website.



Edit: I need the code to always be the version where the user is not logged in.










share|improve this question









New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • check for the content which is available only for the logged-in users...?

    – holex
    12 hours ago











  • I need contents of when the user is not logged in.

    – Seifer
    12 hours ago











  • In many cases the login information is stored in a cookie. If this is the case use URLSession and URLRequest which is able to ignore cookies. (httpShouldHandleCookies = false). The API String(contentsOf for a remote URL is inappropriate anyway. And why do you cast a String to a String?

    – vadian
    12 hours ago













  • you know, your question does not make any sense at all... if you don't know what you are looking for, how does anyone else would know...? your question in its current state cannot be answered at all – speculations can be made only.

    – holex
    12 hours ago













  • @holex I know what I want. I want to get the html code of a website. But the problem is the code is different depending on if I am logged in to the website. I want the code of a non-logged in user.

    – Seifer
    12 hours ago
















0















I am trying to scrape html code from a URL using Swift, but it needs to be done anonymously.
The issue with my case is that the content differs when I am logged in the website or not. My app has a webkit that allows users to view a certain page of a website. If they log in via the webkit, the scraping result is different from if they did not log in.



I have read and searched through tons of questions on StackOverflow to see how to get the HTML source from a URL and the one that I am using can be found here:
How To Get HTML source from URL with Swift I have also tried the codes from different answers and questions.



guard let getHTMLString = try? String(contentsOf: theUrl, encoding: .utf8).condensingWhitespace() as String else {
callErrorPage()
return
}


I get the content of the html page with the code above.



But like I mentioned above, the codes differ if the user has logged in the website.



Edit: I need the code to always be the version where the user is not logged in.










share|improve this question









New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • check for the content which is available only for the logged-in users...?

    – holex
    12 hours ago











  • I need contents of when the user is not logged in.

    – Seifer
    12 hours ago











  • In many cases the login information is stored in a cookie. If this is the case use URLSession and URLRequest which is able to ignore cookies. (httpShouldHandleCookies = false). The API String(contentsOf for a remote URL is inappropriate anyway. And why do you cast a String to a String?

    – vadian
    12 hours ago













  • you know, your question does not make any sense at all... if you don't know what you are looking for, how does anyone else would know...? your question in its current state cannot be answered at all – speculations can be made only.

    – holex
    12 hours ago













  • @holex I know what I want. I want to get the html code of a website. But the problem is the code is different depending on if I am logged in to the website. I want the code of a non-logged in user.

    – Seifer
    12 hours ago














0












0








0








I am trying to scrape html code from a URL using Swift, but it needs to be done anonymously.
The issue with my case is that the content differs when I am logged in the website or not. My app has a webkit that allows users to view a certain page of a website. If they log in via the webkit, the scraping result is different from if they did not log in.



I have read and searched through tons of questions on StackOverflow to see how to get the HTML source from a URL and the one that I am using can be found here:
How To Get HTML source from URL with Swift I have also tried the codes from different answers and questions.



guard let getHTMLString = try? String(contentsOf: theUrl, encoding: .utf8).condensingWhitespace() as String else {
callErrorPage()
return
}


I get the content of the html page with the code above.



But like I mentioned above, the codes differ if the user has logged in the website.



Edit: I need the code to always be the version where the user is not logged in.










share|improve this question









New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am trying to scrape html code from a URL using Swift, but it needs to be done anonymously.
The issue with my case is that the content differs when I am logged in the website or not. My app has a webkit that allows users to view a certain page of a website. If they log in via the webkit, the scraping result is different from if they did not log in.



I have read and searched through tons of questions on StackOverflow to see how to get the HTML source from a URL and the one that I am using can be found here:
How To Get HTML source from URL with Swift I have also tried the codes from different answers and questions.



guard let getHTMLString = try? String(contentsOf: theUrl, encoding: .utf8).condensingWhitespace() as String else {
callErrorPage()
return
}


I get the content of the html page with the code above.



But like I mentioned above, the codes differ if the user has logged in the website.



Edit: I need the code to always be the version where the user is not logged in.







html ios swift






share|improve this question









New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 7 hours ago









Mr.Kushwaha

474511




474511






New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 12 hours ago









SeiferSeifer

42




42




New contributor




Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Seifer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • check for the content which is available only for the logged-in users...?

    – holex
    12 hours ago











  • I need contents of when the user is not logged in.

    – Seifer
    12 hours ago











  • In many cases the login information is stored in a cookie. If this is the case use URLSession and URLRequest which is able to ignore cookies. (httpShouldHandleCookies = false). The API String(contentsOf for a remote URL is inappropriate anyway. And why do you cast a String to a String?

    – vadian
    12 hours ago













  • you know, your question does not make any sense at all... if you don't know what you are looking for, how does anyone else would know...? your question in its current state cannot be answered at all – speculations can be made only.

    – holex
    12 hours ago













  • @holex I know what I want. I want to get the html code of a website. But the problem is the code is different depending on if I am logged in to the website. I want the code of a non-logged in user.

    – Seifer
    12 hours ago



















  • check for the content which is available only for the logged-in users...?

    – holex
    12 hours ago











  • I need contents of when the user is not logged in.

    – Seifer
    12 hours ago











  • In many cases the login information is stored in a cookie. If this is the case use URLSession and URLRequest which is able to ignore cookies. (httpShouldHandleCookies = false). The API String(contentsOf for a remote URL is inappropriate anyway. And why do you cast a String to a String?

    – vadian
    12 hours ago













  • you know, your question does not make any sense at all... if you don't know what you are looking for, how does anyone else would know...? your question in its current state cannot be answered at all – speculations can be made only.

    – holex
    12 hours ago













  • @holex I know what I want. I want to get the html code of a website. But the problem is the code is different depending on if I am logged in to the website. I want the code of a non-logged in user.

    – Seifer
    12 hours ago

















check for the content which is available only for the logged-in users...?

– holex
12 hours ago





check for the content which is available only for the logged-in users...?

– holex
12 hours ago













I need contents of when the user is not logged in.

– Seifer
12 hours ago





I need contents of when the user is not logged in.

– Seifer
12 hours ago













In many cases the login information is stored in a cookie. If this is the case use URLSession and URLRequest which is able to ignore cookies. (httpShouldHandleCookies = false). The API String(contentsOf for a remote URL is inappropriate anyway. And why do you cast a String to a String?

– vadian
12 hours ago







In many cases the login information is stored in a cookie. If this is the case use URLSession and URLRequest which is able to ignore cookies. (httpShouldHandleCookies = false). The API String(contentsOf for a remote URL is inappropriate anyway. And why do you cast a String to a String?

– vadian
12 hours ago















you know, your question does not make any sense at all... if you don't know what you are looking for, how does anyone else would know...? your question in its current state cannot be answered at all – speculations can be made only.

– holex
12 hours ago







you know, your question does not make any sense at all... if you don't know what you are looking for, how does anyone else would know...? your question in its current state cannot be answered at all – speculations can be made only.

– holex
12 hours ago















@holex I know what I want. I want to get the html code of a website. But the problem is the code is different depending on if I am logged in to the website. I want the code of a non-logged in user.

– Seifer
12 hours ago





@holex I know what I want. I want to get the html code of a website. But the problem is the code is different depending on if I am logged in to the website. I want the code of a non-logged in user.

– Seifer
12 hours ago












1 Answer
1






active

oldest

votes


















0














It will always do this anonymously :



var request = URLRequest(url: URL(string: "http://google.com")!)
request.httpMethod = "GET"
let session = URLSession.init(configuration: URLSessionConfiguration.default)
session.dataTask(with: request) {data,response,error in
if let data = data {
let contents = String(data: data, encoding: .ascii)
}
}.resume()





share|improve this answer








New contributor




Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    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
    });


    }
    });






    Seifer is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54249859%2fhow-to-get-html-source-from-url-in-swift-anonymously%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














    It will always do this anonymously :



    var request = URLRequest(url: URL(string: "http://google.com")!)
    request.httpMethod = "GET"
    let session = URLSession.init(configuration: URLSessionConfiguration.default)
    session.dataTask(with: request) {data,response,error in
    if let data = data {
    let contents = String(data: data, encoding: .ascii)
    }
    }.resume()





    share|improve this answer








    New contributor




    Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      0














      It will always do this anonymously :



      var request = URLRequest(url: URL(string: "http://google.com")!)
      request.httpMethod = "GET"
      let session = URLSession.init(configuration: URLSessionConfiguration.default)
      session.dataTask(with: request) {data,response,error in
      if let data = data {
      let contents = String(data: data, encoding: .ascii)
      }
      }.resume()





      share|improve this answer








      New contributor




      Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        0












        0








        0







        It will always do this anonymously :



        var request = URLRequest(url: URL(string: "http://google.com")!)
        request.httpMethod = "GET"
        let session = URLSession.init(configuration: URLSessionConfiguration.default)
        session.dataTask(with: request) {data,response,error in
        if let data = data {
        let contents = String(data: data, encoding: .ascii)
        }
        }.resume()





        share|improve this answer








        New contributor




        Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        It will always do this anonymously :



        var request = URLRequest(url: URL(string: "http://google.com")!)
        request.httpMethod = "GET"
        let session = URLSession.init(configuration: URLSessionConfiguration.default)
        session.dataTask(with: request) {data,response,error in
        if let data = data {
        let contents = String(data: data, encoding: .ascii)
        }
        }.resume()






        share|improve this answer








        New contributor




        Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 12 hours ago









        EmreEmre

        765




        765




        New contributor




        Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Emre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






















            Seifer is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Seifer is a new contributor. Be nice, and check out our Code of Conduct.













            Seifer is a new contributor. Be nice, and check out our Code of Conduct.












            Seifer is a new contributor. Be nice, and check out our Code of Conduct.
















            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%2f54249859%2fhow-to-get-html-source-from-url-in-swift-anonymously%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

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre