Как исправить IndexError: list index out of range
Я делаю зачистку, но если мой сценарий не может что-то найти, он выдаст эту ошибку
IndexError: list index out of range
Я хочуЧтобы перейти к следующей ссылке, не прерывайте, но мой сценарий прерывается и не идет со вторым URL
Вот мой код Python:
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
plus = "+ "
with open("Sans Fransico.csv","r") as s:
s.read()
df = pd.read_csv('Yelp+Scraping_Sans+Fransico.csv') # Get all the urls from the excel
mylist = df['Urls'].tolist() #urls is the column name
driver = webdriver.Chrome()
for url in mylist:
driver.get(url)
wevsite_link = driver.find_elements_by_css_selector(".text--offscreen__373c0__1SeFX+ .link-size--default__373c0__1skgq")
phone = driver.find_elements_by_css_selector(".text--offscreen__373c0__1SeFX+ .text-align--left__373c0__2pnx_")
items = len(wevsite_link)
with open("Sans Fransico.csv", 'a',encoding="utf-8") as s:
for i in range(items):
if wevsite_link[i].text == '':
s.write(phone[i].text + "\n")
if [i] == '':
s.write('N' + "," + 'N' + "\n")
s.write('N' + "," + 'N' + "\n")
if wevsite_link[i].text == '' and phone[i].text == '':
s.write('' + "," + '' + "\n")
else:
s.write(phone[i].text + "," + wevsite_link[i].text + "\n")
driver.close()
print ("Done")
ОШИБКА:
Traceback (most recent call last):
File ".\seleniuminform.py", line 36, in <module>
s.write(phone[i].text + "," + wevsite_link[i].text + "\n")
IndexError: list index out of range