我正在做一个保险网页的网络爬虫,它在 CSV 中检索我的模型、品牌、子品牌和描述,当我运行我的代码时,有时它可以工作,有时它会给我多个错误(“列表索引必须是整数", "期望值:第 1 行第 1 列", "JSON 解码器不工作")
我尝试插入打印件并尝试查看问题出在哪里,但仍然没有得到它。
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
慕森王
相关分类