如何修复(索引错误:列表索引超出范围)python 2和3?[已关闭]

vmdwslir  于 2023-03-06  发布在  Python
关注(0)|答案(1)|浏览(3727)

19小时前关门了。
此帖子已在17小时前编辑并提交审阅,未能重新打开帖子:
原始关闭原因未解决
Improve this question
我有这个密码

# -*- coding: utf-8 -*-

import requests
import re

url = requests.get('https://rotana.net/%D8%AC%D8%AF%D9%88%D9%84-%D8%A7%D9%84%D8%A8%D8%B1%D8%A7%D9%85%D8%AC/')
date = re.findall(r'csv\":\"https:\\\/\\\/rotana.net\\\/triAssets\\\/uploads\\\/(\d{4}\W{2}\d{2})\W{2}', url.text)[0].replace('\/', '/')
channel_code = re.findall(r'/\d+\\/\d+\\/(.*?).csv\"', url.text)
channel_code = [ch for ch in channel_code if not '.png' in ch]
for code in channel_code:
    rotana(date, code)

我在python 3上遇到了这个错误

IndexError: list index out of range

我正在尝试获取E2 python设备的最后EPG数据...

qlckcl4x

qlckcl4x1#

您可以将try except与IndexError一起使用来修复此问题

try:
    date = re.findall(regex_pattern)[0].replace('\/', '/')
except IndexError:
    print("Date not found!")
    exit()

相关问题