Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

How to Parse HTML on iOS

This is a blog post by iOS Tutorial Team member Matt Galloway, founder of SwipeStack, a mobile development team based in London, UK. You can also find me on Google+. Let’s say you want to find some information inside a web page and display it in a custom way in your app. This technique is […]


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2899-how-to-parse-html-on-ios

nice concept…but i need this code in swift, how do i get that?

We update tutorials as quickly as we can. Unfortunately, we haven’t gotten to this one just yet. Apologies for this!

how to display parsed html data in webpage

i want to display only some parts of sections in a webpage
for that i have read the total url contents but stuck with how to display the parsed content in a webpage?
Thanks in advance

since we enter search path for libxml2, will the binary work on another platform that doesn’t have libxml2 in this path? or in any other iphone?

I’ve got anchors with multiple classes - something like <a class=“h5 image js-catalog-click”…

Tried Hpple, Kanna - no luck with XPath like “//a[@class=‘h5 image js-catalog-click’]”

Any ideas how to get the data from such HTML?

Very grateful to the author, and now if you need to use, you need to change a few code, first of all need to change the HTTP for the HTTPS

I changed a place, you can set the author’s head display:grinning:

-(void)loadContributors {
    // 1
    NSURL *contributorsUrl = [NSURL URLWithString:@"https://www.raywenderlich.com/about"];
    NSData *contributorsHtmlData = [NSData dataWithContentsOfURL:contributorsUrl];
    
    // 2
    TFHpple *contributorsParser = [TFHpple hppleWithHTMLData:contributorsHtmlData];
    
    // 3
    NSString *contributorsXpathQueryString = @"//ul[@class='team-members']/li";
    NSArray *contributorsNodes = [contributorsParser searchWithXPathQuery:contributorsXpathQueryString];
    
    // 4
    NSMutableArray *newContributors = [[NSMutableArray alloc] initWithCapacity:0];
    for (TFHppleElement *element in contributorsNodes) {
        // 5
        Contributor *contributor = [[Contributor alloc] init];
        [newContributors addObject:contributor];
        // 6
        //寻找子标签
        for (TFHppleElement *child in element.children) {
            //如果是a  If it is a a tag
            if ([child.tagName isEqualToString:@"a"]) {
                // 7
                //                    contributor.imageUrl = [@"https://www.raywenderlich.com/about" stringByAppendingString:[child objectForKey:@"src"]];
                //继续寻找子标签  Continue to search for child Tags
                for (TFHppleElement *childA in child.children) {
                    //如果是src  If it is src  Here will return the image of URL
                    contributor.imageUrl = [childA objectForKey:@"src"];
                }
                
                    
//                    NSString *str = [temp objectForKey:@"img"];
                
            } else if ([child.tagName isEqualToString:@"h3"]) {
                // 8
                contributor.name = [[child firstChild] content];
            }
        }
    }
    
    // 9
    _contributors = newContributors;
    [self.tableView reloadData];
}

I have made a similar app in android and now I wish to make it in iOS.
In android I have strings file were I have links and other hard-coded texts, is it possible to have reference file like this in iOS?

Hi, I’ve an issue similar to import html content in text field. Here my question.
Thanks in advance

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]