askaale
askaale

Reputation: 1199

Swift read HTML tags from website

Basically I am trying to figure out how I can grab HTML contents of a web page, and store it as variables in my app. I am using a third party service to authenticate a user through a webView. Once the autorization is complete, the server will redirect me to a web page where 3 strings that's necessary for my app to work properly, is stored in HTML like this:

<p> Some value here </p>
<p> Some other value here </p>
<p> The last value goes here </p>

So my question is, how would I proceed in an attempt to grab the text from these paragraphs? I suppose I will have to append each value in an array created "app-side", but I have a hard time figuring out how to simply read/grab the data properly.

Does anyone have an idea on how I might solve this problem?

Thanks in advance.

Upvotes: 0

Views: 660

Answers (1)

M_G
M_G

Reputation: 1208

Use an XML parser to get the content of the nodes you need. Alternatively if you know the HTML exactly you could read the content between the tags by using the HTML string itself. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html

Upvotes: 1

Related Questions