Comment lire une liste d'URLs en Python

Fermé
geekat Messages postés 228 Date d'inscription vendredi 31 juillet 2015 Statut Membre Dernière intervention 24 février 2017 - 27 août 2016 à 17:35
PyMods Messages postés 5 Date d'inscription mardi 30 août 2016 Statut Membre Dernière intervention 16 avril 2017 - 9 sept. 2016 à 22:05
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
A voir également:

2 réponses

PyMods Messages postés 5 Date d'inscription mardi 30 août 2016 Statut Membre Dernière intervention 16 avril 2017 1
9 sept. 2016 à 22:05
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
tuxboy Messages postés 995 Date d'inscription lundi 23 juillet 2012 Statut Membre Dernière intervention 28 mai 2019 190
27 août 2016 à 21:07
Bonjour,

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