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 8562197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:40:46+00:00 2026-06-11T16:40:46+00:00

I am attempting to make a little web crawler in python. What seems to

  • 0

I am attempting to make a little web crawler in python. What seems to be tripping me up right now is the recursive part and depth of this problem. Given a url and a maxDepth of how many sites from there I want to link to I then add the url to the set of searched sites, and download all the text and links from the site. For all the links that the url has in it, I want to search each link and get it’s words and links. What the problem is, is that when I go to recursively call the next url, the depth is already at maxDepth and it stops after going to only 1 more page. Hopefully I explained it decently, basically the question I am asking is how do I do all the recursive calls and then set self._depth += 1?

def crawl(self,url,maxDepth):        

    self._listOfCrawled.add(url)

    text = crawler_util.textFromURL(url).split()

    for each in text:
        self._index[each] = url

    links = crawler_util.linksFromURL(url)

    if self._depth < maxDepth:
        self._depth = self._depth + 1
        for i in links:
            if i not in self._listOfCrawled:
                self.crawl(i,maxDepth) 
  • 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-11T16:40:47+00:00Added an answer on June 11, 2026 at 4:40 pm

    The problem with your code is that you increase self.depth each time you call the function, and since it is a variable of the instance, it stays increased in the following calls. Let’s say maxDepth is 3 and you have a URL A that links to pages B, and C, and B links to D, and C has a link to E. Your call hierarchy then looks like this (assuming that self._depth is 0 at the beginning):

    crawl(self, A, 3)          # self._depth set to 1, following links to B and C
        crawl(self, B, 3)      # self._depth set to 2, following link to D
            crawl(self, D, 3)  # self._depth set to 3, no links to follow
        crawl(self, C, 3)      # self._depth >= maxDepth, skipping link to E
    

    In other words, instead of the depth of the current call, you track the accumulated number of calls to crawl.

    Instead, try something like this:

    def crawl(self,url,depthToGo):
        # call this method with depthToGo set to maxDepth
        self._listOfCrawled.add(url)
        text = crawler_util.textFromURL(url).split()
        for each in text:
            # if word not in index, create a new set, then add URL to set
            if each not in self._index:
                self._index[each] = set([])
            self._index[each].add(url)
        links = crawler_util.linksFromURL(url)
        # check if we can go deeper
        if depthToGo > 0:
            for i in links:
                if i not in self._listOfCrawled:
                    # decrease depthToGo for next level of recursion
                    self.crawl(i, depthToGo - 1) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a python package of the following hierarchy: \standard \__init__.py \text.txt
I was attempting to make some expression templates as an answer to this question
Im attempting to make a little app that lets you add text boxes to
I'm attempting to make a PDF from a HTML document, and this document has
I am attempting to make an algorithm to solve Project Euler Problem 255 I
Attempting to make a NSObject called 'Person' that will hold the login details for
I'm attempting to make a simple linear text game that will display inside a
I am attempting to make my first mobile website by just using a different
I am attempting to make ValidationSummary in Silverlight scrollable. It does not work and
I'm attempting to make a StateMachine execute some database action between states. So I

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.