Comment lire une liste d'URLs en Python

geekat Messages postés 223 Date d'inscription   Statut Membre Dernière intervention   -  
PyMods Messages postés 7 Statut Membre -
Bonjour,

J'ai une URL que je réussis à lire en Python.
J'ai essayé de faire de même pour une liste d'URLs mais ça ne marche pas du tout. Ma liste est sous cette forme : liste =['https://fr.wiktionary.org/w/api.php?action=query&titles=ablafardir&prop=iwlinks&utf8&iwprefix=en&format=json&indexpageids=1687421', 'https://fr.wiktionary.org/w/api.php?action=query&titles=ablater&prop=iwlinks&utf8&iwprefix=en&format=json&indexpageids=249004']

Je ne vois pas pourquoi y a un problème.
Voici le code :
for i in liste:
    with urllib.request.urlopen(i)as url:
        datas= json.loads(url.read().decode('utf8'))
        print(datas


Aidez-moi SVP.
Merci

2 réponses

  1. PyMods Messages postés 7 Statut Membre 1
     
    Salut,

    essaye ce code :

    liste =['https://fr.wiktionary.org/w/api.php?action=query&titles=ablafardir&prop=iwlinks&utf8&iwprefix=en&format=json&indexpageids=1687421', 'https://fr.wiktionary.org/w/api.php?action=query&titles=ablater&prop=iwlinks&utf8&iwprefix=en&format=json&indexpageids=249004']
    i = 0

    while i < len(liste):
    print(liste[i])
    i += 1

    input()
    0
  2. tuxboy Messages postés 1083 Statut Membre 190
     
    Bonjour,

    Tu peux essayer :
    print '\n'.join(["%ss" % (l) for l in liste])
    -1