Bonjour,

J'essaie de créer une fonction Crawl avec un paramètre DEPTH.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def crawl(root, depth):
    urls = root
    visited = []
    counter = 0
 
    while counter < depth:
        step_url = extraire_liens(urls)
        urls = [] 
        for u in step_url:
            if u not in visited:
                urls.append(u)
                visited.append(u)
            counter +=1
    return visited
le résultat de step_url :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
['https://www.google.com', 'http://schema.org', 'https://play.google.com', 'https://accounts.google.com', 'https://www.youtube.com', 'https://maps.google.fr', 'https://mail.google.com', 'https://drive.google.com', 'https://news.google.fr', 'http://www.google.fr', 'https://www.google.fr']


Mais il semble que la fonction ne va pas plus loin que le niveau 1 / Profondeur.
Par exemple :
Pour
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
url = 'https://www.google.fr/'
crawl(url, 1)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
['https://www.google.com',
 'http://schema.org',
 'https://play.google.com',
 'https://accounts.google.com',
 'https://www.youtube.com',
 'https://maps.google.fr',
 'https://mail.google.com',
 'https://drive.google.com',
 'https://news.google.fr',
 'http://www.google.fr',
 'https://www.google.fr']
Mais pour le niveau 2/Profondeur, aucuns changements.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
url = 'https://www.google.fr/'
crawl(url, 2)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
['https://www.google.com',
 'http://schema.org',
 'https://play.google.com',
 'https://accounts.google.com',
 'https://www.youtube.com',
 'https://maps.google.fr',
 'https://mail.google.com',
 'https://drive.google.com',
 'https://news.google.fr',
 'http://www.google.fr',
 'https://www.google.fr']
Où est l'erreur ?