0

I'm getting an odd error message saying "Extra argument 'endocing' in call", but it's in the method, so it's not an extra argument? Why is this happening and how can I resolve this? The error message appears when declaring the variable "parser" as you can see. Thanks!

if let checkedUrl = NSURL(string:"http://www.mobladet.se") { if let htmlString = String(contentsOfURL: checkedUrl, encoding: NSUTF8StringEncoding, error: nil) { // Parsing HTML let opt = CInt(HTML_PARSE_NOERROR.value | HTML_PARSE_RECOVER.value) var err : NSError? var parser = HTMLParser(html: htmlString, encoding: NSUTF8StringEncoding, option: opt, error: &err) var bodyNode = parser.body // Create an array of the part of HTML you need if let inputNodes = bodyNode?.findChildTags("h4") { for node in inputNodes { let result = html2String(node.rawContents) println(result) } } } else { println("Could not load HTML Content") } } 
4
  • 1
    html should be HTML code to be parsed not a NSURL Commented Feb 26, 2015 at 19:43
  • 1
    You need to fetch your NSURL content and them parse it Commented Feb 26, 2015 at 19:43
  • Yes, I follow you now, sorry for being so stupid =( Could you please give me a short example of I should do that? Many thanks! Commented Feb 26, 2015 at 19:47
  • 1
    @ look at my posted answer Commented Feb 26, 2015 at 19:48

1 Answer 1

1

html should be HTML code to be parsed not a NSURL. You need to use String( contentsOfURL:) to extract its contents and them parse it

if let checkedUrl = NSURL(string:"http://stackoverflow.com/questions/28751228/a-swift-wrapper-around-libxml-for-parsing-html"){ if let htmlString = String(contentsOfURL: checkedUrl, encoding: NSUTF8StringEncoding, error: nil) { println(htmlString) } else { println("could not load html string from the url") } } else { println("invalid url") } 
Sign up to request clarification or add additional context in comments.

10 Comments

String returns an optional string you should safely unwrap your url and your string just in case one of them returns nil
Thanks! It works now =) Sorry for asking again, but I'm new to this parsing thing =) How could I get the title of this post: <h4 class="widget-title">Senaste nyheterna</h4><ul><li><a href="mellanosternbladet.se/… Ali Khameneis brev till unga i väst"</a><span class="post-date">4 februari, 2015</span></li>
I have already answered that many times I will find the answer if it solves the problem just up vote it
I have edited above linked answer and included the NSAttributedString extension also
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.