-1

このコードを書きましたが、最後の行を実行した後、「IndexError: list index out of range」というエラーが表示されました。どうすればこれを修正できますか?

    import requests
    from bs4 import BeautifulSoup

    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, 
                                           like Gecko) Chrome/61.0.3163.100 Safari/537.36'}
    response = requests.get("https://www.zomato.com/bangalore/top-restaurants",headers=headers)

    content = response.content
    soup = BeautifulSoup(content,"html.parser")

    top_rest = soup.find_all("div",attrs={"class": "sc-bblaLu dOXFUL"})
    list_tr = top_rest[0].find_all("div",attrs={"class": "sc-gTAwTn cKXlHE"})

list_rest =[]
for tr in list_tr:
    dataframe ={}
    dataframe["rest_name"] = (tr.find("div",attrs={"class": "res_title zblack bold nowrap"})).text.replace('\n', ' ')
    dataframe["rest_address"] = (tr.find("div",attrs={"class": "nowrap grey-text fontsize5 ttupper"})).text.replace('\n', ' ')
    dataframe["cuisine_type"] = (tr.find("div",attrs={"class":"nowrap grey-text"})).text.replace('\n', ' ')
    list_rest.append(dataframe)
list_rest
4

3 に答える 3