Grab text only from Wordpress website, display on iOS app Grab text only from Wordpress website, display on iOS app wordpress wordpress

Grab text only from Wordpress website, display on iOS app


You are using a ready-made app so I think, you will have to modify it yourself to serve your purpose. For showing content as you want, you need to manipulate the HTML content instead of viewing it in WebView.

Inside your app, the WebView element is in PostViewController.swift file. So if your put the following code in line number 24 of that file, you will get the URL that is being requested.

println(url)

This code prints the output in console. Now as you know the url. You can simply fetch the HTML Code and manipulate and show it as your heart want using the following way:

let pageurl = NSURL(string: url) //you got the url variable 3 lines abovelet task = NSURLSession.sharedSession().dataTaskWithURL(pageurl!) {(data, response, errror) in if error == nil {var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding) as NSString!println(urlContent)}}

This will print the full HTML Code string encoded using UTF-8.

Now in the postViewController, instead of using WebView element, you can use a label, or textbox or whatever you want to show your content inside. Then create an outlet for that element. And then manipulate the HTML Code String by following way:

var urlContentArray = urlContent?.componentSeparatedByString("<span class=\"storybyline\">") // In your website (vikinglogue.com) your author name is inside this span element.println(urlContentArray[1]) // This will print everything after that span section in your consolevar authorArray = urlContentArray[1].componentSeparatedByString("</span>")var author = authorArray[0]

Now you have the author name and you can show it in any textbox or label or in any element that support text. You can grab all other info from that page in the same way. I hope it helped.


Since RSS comes in a structured XML format, you can simply fetch your page's rss feed and parse the elements for the needed data. To see some how to code, you may check out mwaterfalls' Feedparser

e.g

<title>Girls softball dominating early</title><link>http://vikinglogue.com/2377/sports/girls-softball-dominating-early/</link><comments>http://vikinglogue.com/2377/sports/girls-softball-dominating-early/#comments</comments><pubDate>Wed, 22 Apr 2015 21:54:32 +0000</pubDate>