Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:36:52+00:00 2026-06-07T16:36:52+00:00

So I’m using HPPLE to do some Xpath queries in a iOS app that

  • 0

So I’m using HPPLE to do some Xpath queries in a iOS app that needs to do some basic web scraping of a few sites. Right now everything works pretty good, but I wanted to see if there’s another, more elegant way of doing what I’m doing. Currently what I’m doing is that I’m using XPath to find a specific div class in a website, within that website (which is basically like a post) there can be any number of children that have text, and others that have text buried in another set of children. Right now I’m basically using repeated For Loops to check if the "text" tagName exists and if so add that value to a string and if not then check if there is another level of children that need to be scanned and I have 4 levels so far of the same search. I was wondering if there is some method that I can run that will redo the same search if the count of children within the current level is greater than 0. Below is the code for how I’m doing this now

 for (TFHppleElement *element in searchNodes) {
    //If a Text Node is found add it to the String, if not search again with next layer
    if ([element.tagName isEqualToString:@"text"]) {
        [bigString appendString:element.content];
    }
    //1. First layer Scan
    if (element.children.count > 0) {
        for (TFHppleElement *nextStep in element.children) { 
            if ([nextStep.tagName isEqualToString:@"text"]) {
                [bigString appendString:nextStep.content];
            }
            
            //2. Second layer Scan
            if (nextStep.children.count > 0) {
                for (TFHppleElement *child in nextStep.children) { 
                    if ([child.tagName isEqualToString:@"text"]) {
                        [bigString appendString:child.content];
                        
                    }
                    
                    //3. Thrid Layer Scan
                    if (child.children.count > 0) {
                        for (TFHppleElement *children in child.children) { 
                            if ([children.tagName isEqualToString:@"text"]){
                                [bigString appendString:children.content];
                            }
                            
                            //4. Fourth Layer Scan
                            if (children.children.count > 0) {
                                for (TFHppleElement *newchild in children.children){
                                    if ([newchild.tagName isEqualToString:@"text"]) {
                                        [bigString appendString:newchild.content];
                                        
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

I would like to have some kind of method build that I can just basically send over the initial NSArray and then it’s checks for additional elements and then performs the search again with the next array all while continuing to build up a NSMutableString that will end up with all the text from every search. If not, what I have now seems to be working fine, I just wanted to see if there was a cleaner way of doing this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:36:53+00:00Added an answer on June 7, 2026 at 4:36 pm

    I think what you want is recursion. You can write a recursive method that you pass an element to, have it modify some NSMutableString outside itself (an instance variable, maybe?), then call itself with its own children if it can. For example (uncompiled, untested):

    @property (nonatomic, retain) NSMutableString * bigString;
    // snip
    @synthesize bigString;
    // snip - assume bigString gets initialized somewhere
    
    - (void)checkElement:(TFHppleElement *)elem {
        if ([element.tagName isEqualToString:@"text"]) {
            [bigString appendString:elem.content];
        }
    
        if (element.children.count > 0) {
            for (TFHppleElement * child in element.children) {
                [self checkElement:child];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.