With my code I can extract information from all my sessions. All is okey but somethimes I have an error: xml.etree.ElementTree.ParseError: mismatched tag: line 22, column 6. I want to edit my code to correct such errors. And if it is possible any error that there is from the execution of the function until the end of each session
# encoding=utf8
# -*- coding: utf-8 -*-
import random
import xml.etree.ElementTree as ET
import requests
from requests.auth import HTTPBasicAuth
import sys
import csv
reload(sys)
sys.setdefaultencoding('utf-8')
lista = []
number = str(random.random())
cuenta = ['@a.com', '@b.com', '@c','@d', '@e', '@f']
for item in cuenta:
user = 'user{}'.format(item)
passwd = 'pass'
url = 'url'
login = requests.get(url, auth=HTTPBasicAuth(user, passwd))
url_sitios = 'url_sitios'
sitios = requests.get(url_sitios, auth=HTTPBasicAuth(user, passwd))
sitios2 = sitios.text
root = ET.fromstring(sitios2)
for s in root.findall('sitio'):
id = s.find('sitio_id')
fa = s.find('fecha_alta')
i24 = s.find('*/item[@id="imps24ad"]') # Impresiones Vendidas ultimas 24HS
estado = s.find('estado')
url = s.find('url')
nombre = s.find('nombre')
a = id.text # id del Sitio
b = fa.text # Fecha de alta
c = i24.text # Ultimas 24hs Impresiones
d = estado.text # Estado
e = url.text # url
f = nombre.text # nombre
sitio = str(a), str(b), str(c), str(d), str(e), str(f)
sitio_ok = (list(sitio))
ff = lista.append(sitio_ok)
print ff
requests.get('url_out' + number + '&o=xml', auth=HTTPBasicAuth(user, passwd))
with open("data.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(lista)
requests? It seems like there's significant room to reduce this question's scope, and thereby to improve its conformance with the minimal reproducible example definition (which calls for posting only the shortest possible complete, standalone code that lets someone reproduce a problem).lxml.htmlis a good place to start, or Beautiful Soup).