My simple solution to Homework 3.7 (without extra-class stuff)

I think mine is a little different from what I've seen here, so here it is:

def crawl_web(seed,max_depth):
    depth = 0
    tocrawl = [(seed, depth)] # each element is a pair: (url, depth from seed)
    crawled = []
    while tocrawl:
        page, depth = tocrawl.pop(0)   # would work with .pop() too but outputs different order
        if page not in crawled and depth <= max_depth:
            links = get_all_links(get_page(page))
            while links:
                tocrawl.append((links.pop(), depth + 1))
            crawled.append(page)
    return crawled

asked 14 Mar '12, 15:28

Nuno's gravatar image

Nuno
188311
accept rate: 0%

Nice method.. :-)

(14 Mar '12, 16:02) Dhiraj Dhiraj's gravatar image
Be the first one to answer this question!
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,238
×161
×114

Asked: 14 Mar '12, 15:28

Seen: 171 times

Last updated: 14 Mar '12, 16:02