I'm doing a web scraper of an insurance webpage that retrieves me in a CSV the model, brand, subbrand, and the description and when I run my code sometimes it works and other times gives me multiple errors ( "list indices must be integers", "Expecting value: line 1 column 1", "JSON decoder is not working")
I've tried to insert prints and try to see where was the problem but still not get it.
import requests
import time
import json
session = requests.Session()
request_marcas = session.get('https://www.citibanamexchubb.com/api/chubbnet/auto/brands-subbrands')
data = request_marcas.json()
fileCSV = open("webscraper_test.csv", "a")
fileCSV.write('Modelo' + ';' + 'ID_Marca' + ";" + 'ID_Submarca' + ";" + "ID_Tipo" + ";" + "Marca" +";"+ "Tipo"+ 'Descripcion' + "\n")
for i in range(2019, 2020):
for marca in data['MARCA']:
for submarca in marca['SUBMARCAS']:
modelos = []
modelos.append('https://www.citibanamexchubb.com/api/chubbnet/auto/models/' + marca['ID'] + '/' + submarca['ID'] + '/' + str(i))
for link in modelos:
json_link = []
request_link = session.get(link).json()
json_link.append(request_link)
#print(request_link)
for desc_id in request_link['TIPO']:
#print(desc_id['ID'])
desc_detail = []
desc_detail.append(session.get('https://www.citibanamexchubb.com/api/chubbnet/auto/descriptions/' + desc_id['ID'] + '/2018').json())
#print(desc_detail)
try:
for desc in desc_detail['DESCRIPCION']:
print(desc['DESC'])
except Exception as e:
None