0

I have a python script on my webserver which simply prints out 2 to 5 words, one under the other.

Ruyterplaats
Civic Centre
Racecourse
Atlantis

What I need to do is the following:

  • open the url www.webserveraddress.com?variable1=variable2
  • get the words from each line and put them into an array

No need to display the webpage, I just need the words. Thats all.

Iv seen I can use things like Libxml2 and Hpple, but these are ObjC wrappers around other code. I'm not sure how Swift will cope with that.

I quite frankly have no idea where to start or even if I'm going about it the wrong or not :/

PS. I would post code but the python script is around 6500 lines :)

1 Answer 1

1

The quickest way to get the contents of a URL as a string is to use the constructor on NSString:

var contents = NSString(contentsOfURL: NSURL(string: "http://example.com"), encoding: NSUTF8StringEncoding, error: nil)

Then you can separate the contents into an array using componentsSeparatedByCharactersInSet:

var wordArray = contents.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())

Note: The server side technology doesn't matter at all, which is one of the best things about the HTTP protocol ;). That URl could return a static file for all the Swift code (or anyone else) will care.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.