-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebscrap.py
More file actions
385 lines (366 loc) · 26.9 KB
/
webscrap.py
File metadata and controls
385 lines (366 loc) · 26.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import getpass
import datetime
from datetime import datetime, date
import os
import time
import shutil
username = getpass.getuser()
from django.conf import settings
import django
from project.settings import DATABASES, INSTALLED_APPS
settings.configure(DATABASES=DATABASES, INSTALLED_APPS=INSTALLED_APPS)
django.setup()
from Paralegapp.models import *
fecha = datetime.now().strftime("%Y/%m/%d, %H:%M:%S")
fecha2 = datetime.now()
casos = Caso.objects.order_by('last_chek')
#poner condicion de solo casos activos
if casos.count() > 0:
options = webdriver.ChromeOptions()
#options.add_experimental_option('prefs', {
#"download.default_directory": path4, # Change default directory for downloads
#"download.prompt_for_download": False, # To auto download the file
#"download.directory_upgrade": True,
#"plugins.always_open_pdf_externally": True, # It will not show PDF directly in chrome
# "profile.default_content_settings.popups": 0
#})
browser = webdriver.Chrome(executable_path=r'C:\\Users\\' + username + '\\Desktop\\chromedriver\\chromedriver.exe', options=options)
#---------------open casos pagina
browser.get('https://civil.pjud.cl/CIVILPORWEB/')
# esperar que carge
wait = WebDriverWait(browser, 120)
wait.until(EC.presence_of_element_located((By.XPATH, '/html/frameset/frameset/frame[2]')))
#----------------------- cambiar al inner HTML
bframe = browser.find_element_by_xpath('/html/frameset/frameset/frame[2]')
browser.switch_to.frame(bframe)
main = browser.current_window_handle
cuenta = 0
cambios = 0
# css : body > form > table:nth-child(10) > tbody > tr > td:nth-child(2) > a:nth-child(2) > img xpath: /html/body/form/table[6]/tbody/tr/td[2]/a[2]/img
try:
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > form > table:nth-child(10) > tbody > tr > td:nth-child(2) > a:nth-child(2) > img')))
pos = str(10)
except:
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > form > table:nth-child(9) > tbody > tr > td:nth-child(2) > a:nth-child(2) > img')))
pos = str(9)
#----------------------recorre todos los casos para actualizarlos
casocontador = 0
for caso in casos.all():
try:
cuenta = cuenta + 1
if cuenta == 42:
#------------- open casos pagina
browser.close()
browser.quit()
browser = webdriver.Chrome(executable_path=r'C:\\Users\\' + username + '\\Desktop\\chromedriver\\chromedriver.exe', options=options)
browser.get('https://civil.pjud.cl/CIVILPORWEB/')
wait = WebDriverWait(browser, 120)
#----------- esperar que carge /html /html/frameset/frameset/frame[2]
wait.until(EC.presence_of_element_located((By.XPATH, '/html/frameset/frameset/frame[2]')))
#----------- cambiar al inner HTML
bframe = browser.find_element_by_xpath('/html/frameset/frameset/frame[2]')
browser.switch_to.frame(bframe)
cuenta = 0
tipo = caso.rol
rol = caso.numero
ano = caso.year
tribunal = caso.tribunal.tribunal
try:# css : body > form > table:nth-child(10) > tbody > tr > td:nth-child(2) > a:nth-child(2) > img xpath: /html/body/form/table[6]/tbody/tr/td[2]/a[2]/img
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > form > table:nth-child(' + pos + ') > tbody > tr > td:nth-child(2) > a:nth-child(2) > img')))
except:
# open casos pagina
browser.close()
browser.quit()
browser = webdriver.Chrome(executable_path=r'C:\\Users\\' + username + '\\Desktop\\chromedriver\\chromedriver.exe', options=options)
browser.get('https://civil.pjud.cl/CIVILPORWEB/')
#--------------- esperar que carge
wait = WebDriverWait(browser, 120)
wait.until(EC.presence_of_element_located((By.XPATH, '/html/frameset/frameset/frame[2]')))
#-------------- cambiar al inner HTML
#bframe = browser.find_element_by_xpath('/html/frameset/frameset/frame[2]')
browser.switch_to.frame(bframe)
main = browser.current_window_handle
cuenta = 0
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > form > table:nth-child(' + pos + ') > tbody > tr > td:nth-child(2) > a:nth-child(2) > img')))
#insertar datos del caso para buscar y click en buscar
browser.find_element_by_css_selector('body > form > table:nth-child(' + pos + ') > tbody > tr > td:nth-child(2) > a:nth-child(2) > img').click()
browser.find_element_by_css_selector('#RUC > select').send_keys(tipo)
browser.find_element_by_css_selector('#RUC > input:nth-child(3)').send_keys(rol)
browser.find_element_by_css_selector('#RUC > input:nth-child(4)').send_keys(ano)
##
browser.find_element_by_css_selector('#tribUno > select').send_keys(tribunal)
browser.find_element_by_css_selector('body > form > table:nth-child(' + pos + ') > tbody > tr > td:nth-child(2) > a:nth-child(1) > img').click()
Err = 0
#click en doc encontrado, si no lo encuentra anota "no encontrado" y pasa al proximo
try:
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#contentCellsAddTabla > tbody > tr > td:nth-child(1) > a')))
browser.find_element_by_css_selector('#contentCellsAddTabla > tbody > tr > td:nth-child(1) > a').click()
#-------------espera que carge la pagina
except:
caso.last_chek_coment = 'no se encontro el caso'
browser.execute_script("window.history.go(-1)")
casocontador = casocontador + 1
caso.save()
print(str(casocontador) + caso.last_chek_coment)
continue
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > form > table:nth-child(20) > tbody > tr:nth-child(1) > td:nth-child(1)')))
if caso.dte_nombre == None:
caso.dte_nombre = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(1) > td:nth-child(2)').text
#########arreglar fecha, importante
#caso.fecha_ingreso = datetime.strptime(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(1) > td:nth-child(3)').text[9:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(1) > td:nth-child(3)').text)], '%d/%m/%Y')
########
caso.archivo = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(4) > td:nth-child(2) > img').get_attribute("onclick")[18:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(4) > td:nth-child(2) > img').get_attribute("onclick")) - 2]
caso.est_adm = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(2) > td:nth-child(1)').text[10:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(2) > td:nth-child(1)').text)]
caso.proc = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(2) > td:nth-child(2)').text[7:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(2) > td:nth-child(2)').text)]
caso.ubicacion = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(2) > td:nth-child(3)').text[11:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(2) > td:nth-child(3)').text)]
caso.etapa = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(3) > td:nth-child(1)').text[7:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(3) > td:nth-child(1)').text)]
caso.last_chek = fecha2
estado = browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(3) > td:nth-child(2)').text[13:len(browser.find_element_by_css_selector('body > form > table:nth-child(20) > tbody > tr:nth-child(3) > td:nth-child(2)').text)]
#--------------------------------------ve si el estado del proceso cambio para actualizarlo
R = 0
if estado != caso.estproceso:
caso.estprocnmenos1 = caso.estproceso
caso.estproceso = estado
caso.last_change = fecha2
caso.last_chek_coment = 'cambio en el estado del proceso'
R = 1
#-------------------------------cheuqe cuantos cuaderdos tiene la causa
mycuadernos = browser.find_element_by_css_selector('#TablaCuadernos > tbody > tr > td:nth-child(2) > select')
mycuaderno = browser.find_element_by_css_selector('#TablaCuadernos > tbody > tr > td:nth-child(2) > select > option').text
mycuadopc = mycuadernos.find_elements_by_css_selector('option').__len__()
cuadernos = Casos_t_cuadernos.objects.filter(caso_id=caso.pk)
cuadprev = cuadernos.count()
#----------------------------- si algun cuaderno no esta creado entonces lo crea
if cuadprev != mycuadopc:
g = 1
for cua in range(1, mycuadopc + 1):
ccc = browser.find_element_by_css_selector('#TablaCuadernos > tbody > tr > td:nth-child(2) > select > option:nth-child(' + str(g) + ')').text
existe = Casos_t_cuadernos.objects.filter(caso=caso, cuaderno=ccc).count()
g = g + 1
if existe == 0:
Cuade = Casos_t_cuadernos(caso=caso, numero=cuadprev + 1, cuaderno=ccc, fecha_creacion=fecha2)
Cuade.save()
cuadprev = cuadprev + 1
cuadernos = Casos_t_cuadernos.objects.filter(caso=caso)
#---------------------------recorre todos los cuadernos para revisar si tienen cambios
for cua in cuadernos:
Err = 1
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#Historia > table:nth-child(2)')))
if cua.cuaderno != mycuaderno:
browser.find_element_by_css_selector('#TablaCuadernos > tbody > tr > td:nth-child(2) > select > option:nth-child(' + str(cua.numero) + ')').click()
browser.find_element_by_css_selector('#botoncuaderno > img').click()
mytable = browser.find_element_by_css_selector('#Historia > table:nth-child(2)')
filas = mytable.find_elements_by_css_selector('tr').__len__()
if filas != cua.estado_n:
try:
nuevos = filas - cua.estado_n
except:
nuevos = filas
cua.estado_previo_n = cua.estado_n
cua.estado_n = filas
caso.last_change = fecha2
else:
nuevos = 0
#----------------------si el cuaderno tiene cambios entonces lo actualiza
#if cambios == 1:
b = 2
c = str(b)
G = 0
for m in range(1, nuevos + 1):
fol = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(1)').text
try:
#downloadable = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2) > img').text
element = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2) > img').get_attribute("onclick")
if element.startswith(' ShowPDF'):
srcarchivo = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2) > img').get_attribute("onclick")
src = srcarchivo[18:len(srcarchivo) - 2]
srctype = "pdf"
elif element.startswith('ShowEsc'):
srcarchivo = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2) > img').get_attribute("onclick")
src = srcarchivo[18:len(srcarchivo) - 2]
srctype = 'folder'
else:
src = None
srctype = None
except:
src = None
srctype = None
try:
element2 = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3) > img').get_attribute("onclick")
if element2.startswith(' ShowPDF'):
srcarchivo2 = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3) > img').get_attribute("onclick")
src2 = srcarchivo2[18:len(srcarchivo2) - 2]
srctype2 = "pdf"
elif element2.startswith('ShowEsc'):
srcarchivo2 = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3) > img').get_attribute("onclick")
src2 = srcarchivo2[18:len(srcarchivo2) - 2]
srctype2 = 'folder'
else:
src2 = None
srctype2 = None
except:
src2 = None
srctype2 = None
etapa = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(4)').text
tramite = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(5)').text
desc_t = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(6)').text
datedoc = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(7)').text
foja = browser.find_element_by_css_selector('#Historia > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(8)').text
archivo = str(fol) + '_' + tramite
Err = 2
estnuevo = Estado(tramite=tramite, doc=archivo, etapa=etapa, desc_tramite=desc_t, folio=fol, cuaderno=cua, archivo=src,
tipoarchivo=srctype, foja=foja, fecha_tramite=datedoc, archivo_2=src2, tipoarchivo_2=srctype2, numero_archivo=filas - G)
estnuevo.save()
G = G + 1
if R == 0:
caso.last_chek_coment = 'Estado Nuevo'
elif R == 1:
caso.last_chek_coment = 'Estado Nuevo y cambio en el estado'
b = b + 2
c = str(b)
if nuevos != 0:
cua.save()
LitActuales = Litigante.objects.filter(caso=caso).count()
mytableLit = browser.find_element_by_css_selector('#Litigantes > table:nth-child(2)')
filasLit = mytableLit.find_elements_by_css_selector('tr').__len__()
if LitActuales != filasLit:
browser.find_element_by_css_selector('#tdDos').click()
b = 2
c = str(b)
for t in range(1, filasLit + 1):
part = browser.find_element_by_css_selector('#Litigantes > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(1)').text
rut = browser.find_element_by_css_selector('#Litigantes > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2)').text
persona = browser.find_element_by_css_selector('#Litigantes > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3)').text
nombre = browser.find_element_by_css_selector('#Litigantes > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(4)').text
if LitActuales != 0:
LitActualesList = Litigante.objects.filter(caso=caso)
found2 = 0
for l in LitActualesList:
if l.rut == rut and l.participante == part:
found2 = 1
break
if found2 == 0:
newLit = Litigante(caso=caso, participante=part, rut=rut, persona=persona, nombre=nombre, fecha_creacion=fecha2)
newLit.save()
else:
newLit = Litigante(caso=caso, participante=part, rut=rut, persona=persona, nombre=nombre, fecha_creacion=fecha2)
newLit.save()
b = b + 2
c = str(b)
notiactuales = Notificacion_caso.objects.filter(caso=caso).count()
mytableNot = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2)')
filasnot = mytableNot.find_elements_by_css_selector('tr').__len__()
if notiactuales != filasnot:
browser.find_element_by_css_selector('#tdTres').click()
b = 2
c = str(b)
for t in range(1, filasnot + 1):
Esta_not = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(1)').text
rol = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2)').text
ruc = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3)').text
fechtramite = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(4)').text
tippart = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(5)').text
nombre = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(6)').text
tramite = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(7)').text
obs = browser.find_element_by_css_selector('#Notificaciones > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(8)').text
if notiactuales != 0:
notiactualeslist = Notificacion_caso.objects.filter(caso=caso)
found2 = 0
for n in notiactualeslist:
if n.est_not == Esta_not and n.rol == rol and n.ruc == ruc and n.fectram == fechtramite and n.tip_part == tippart and n.nombre == nombre and n.tramite == tramite:
found2 = 1
break
if found2 == 0:
newnot = Notificacion_caso(est_not=Esta_not, rol=rol, ruc=ruc, fectram=fechtramite, tip_part=tippart, nombre=nombre, tramite=tramite, obs_fallido=obs, fecha_creacion= fecha2)
newnot.save()
else:
newnot = Notificacion_caso(est_not=Esta_not, rol=rol, ruc=ruc, fectram=fechtramite, tip_part=tippart, nombre=nombre, tramite=tramite, obs_fallido=obs, fecha_creacion= fecha2)
newnot.save()
b = b + 2
c = str(b)
escactuales = Esc_por_resolver.objects.filter(caso=caso).count()
mytableesc = browser.find_element_by_css_selector('#Escritos > table:nth-child(2)')
filasesc = mytableesc.find_elements_by_css_selector('tr').__len__()
if escactuales != filasesc:
browser.find_element_by_css_selector('#tdCuatro').click()
b = 2
c = str(b)
for t in range(1, filasnot + 1):
doc = browser.find_element_by_css_selector('#Escritos > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(1)').text
anexo = browser.find_element_by_css_selector('#Escritos > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2)').text
fechaing = browser.find_element_by_css_selector('#Escritos > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3)').text
tipo = browser.find_element_by_css_selector('#Escritos > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(4)').text
solicitante = browser.find_element_by_css_selector('#Escritos > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(5)').text
if escactuales != 0:
escactualeslist = Esc_por_resolver.objects.filter(caso=caso)
found2 = 0
for e in escactualeslist:
if e.doc == doc and e.anexo == anexo and e.fecha_ing == fechaing and e.tipo_escrito == tipo and e.solicitante == solicitante:
found2 = 1
break
if found2 == 0:
newesc = Esc_por_resolver(doc=doc, anexo=anexo, fecha_ing=fechaing, tipo_escrito=tipo, solicitante=solicitante, fecha_creacion=fecha2)
newesc.save()
else:
newesc = Esc_por_resolver(doc=doc, anexo=anexo, fecha_ing=fechaing, tipo_escrito=tipo, solicitante=solicitante, fecha_creacion=fecha2)
newesc.save()
b = b + 2
c = str(b)
exactuales = Exohorto.objects.filter(caso=caso).count()
mytableex = browser.find_element_by_css_selector('#Exhorto > table:nth-child(2)')
filasex = mytableex.find_elements_by_css_selector('tr').__len__()
if exactuales != filasex:
browser.find_element_by_css_selector('#tdCinco').click()
b = 2
c = str(b)
for t in range(1, filasnot + 1):
rolor = browser.find_element_by_css_selector('#Exhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(1)').text
tipoe = browser.find_element_by_css_selector('#Exhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(2)').text
roldes = browser.find_element_by_css_selector('#Ehhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(3)').text
fecord = browser.find_element_by_css_selector('#Ehhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(4)').text
fecing = browser.find_element_by_css_selector('#Ehhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(5)').text
tribdes = browser.find_element_by_css_selector('#Exhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(6)').text
estex = browser.find_element_by_css_selector('#Exhorto > table:nth-child(2) > tbody > tr:nth-child(' + c + ') > td:nth-child(7)').text
if notiactuales != 0:
exactualeslist = Exohorto.objects.filter(caso=caso)
found2 = 0
for n in exactualeslist:
if n.rol_origen == rolor and n.tipo_exohorto == tipoe and n.rol_destino == roldes and n.fecha_ord_exohorto == fecord and n.fecha_ing_exohorto == fecing and n.tribunal_destino == tribdes and n.estado_exohorto == estex:
found2 = 1
break
if found2 == 0:
newex = Exohorto(rol_origen=rolor, tipo_exohorto= tipoe, rol_destino=roldes, fecha_ord_exohorto=fecord, fecha_ing_exohorto= fecing, tribunal_destino= tribdes, estado_exohorto=estex)
newex.save()
else:
newex = Exohorto(rol_origen=rolor, tipo_exohorto= tipoe, rol_destino=roldes, fecha_ord_exohorto=fecord, fecha_ing_exohorto= fecing, tribunal_destino= tribdes, estado_exohorto=estex)
newex.save()
b = b + 2
c = str(b)
caso.last_chek = fecha2
caso.save()
casocontador = casocontador + 1
#volver
browser.execute_script("window.history.go(-2)")
#sheet_obj.cell(row=k, column=16).value = len(os.listdir(path + idefolder))
print(str(casocontador) + caso.last_chek_coment)
except:
caso.last_chek_coment = 'falla en la revision del caso'
caso.last_chek = fecha2
caso.save()
# volver
browser.execute_script("window.history.go(-2)")
casocontador = casocontador + 1
print(str(casocontador) + caso.last_chek_coment)
#borrar carpeta temporal
#salir de browser
print(fecha)
print(datetime.now().strftime("%Y/%m/%d, %H:%M:%S"))
browser.close()
browser.quit()