List index out of range error during data analysis practice with Python example practice for office workers.

Asked 2 years ago, Updated 2 years ago, 46 views

I'm reading a book and practicing Instagram crawling. The error list index out of range appears, but I don't know the cause.

 #4. Date of creation information
    date = soup.select('time._1o9PC.Nzb55')[0]['datetime'][:10]

    #7. Save collection information
    data = [content, date, like, place, tags]
    return data

def move_next(driver):
    right = driver.find_element_by_css_selector('a._65Bje.coreSpriteRightPaginationArrow')
    right.click()
    time.sleep(3)

from selenium import webdriver
from bs4 import BeautifulSoup
import time
import re


driver = webdriver.Chrome('C:/Users/johm7/pp/chromedriver.exe')

Word = "Famous restaurant in Jeju Island."
url = insta_searching(word)

driver.get(url)
time.sleep(3)

select_first(driver)

result = []

target = 500

for i in range(target):
    data = get_content(driver)
    result.append(data)
    move_next(driver)

print(result[:2])

There is an error below in why? I'm reading a book and doing it.

"C:\Program Files (x86)\python\python.exe" C:/Users/johm7/pp/insta_crwal_02.py
Traceback (most recent call last):
  File "C:/Users/johm7/pp/insta_crwal_02.py", line 82, in <module>
    data = get_content(driver)
  File "C:/Users/johm7/pp/insta_crwal_02.py", line 38, in get_content
    date = soup.select('time._1o9PC.Nzb55')[0]['datetime'][:10]
IndexError: list index out of range

Process finished with exit code 1

python crawling

2022-09-21 11:55

1 Answers

You can get the information from the site below. Or ask a question and the author will answer.

https://github.com/Play-with-data/datasalon


2022-09-21 11:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.