У меня проблемы с проектом, над которым я работаю.
У меня есть CSV-файл, в котором все URL-адреса указаны в первом столбце.
Мой скрипт, приведенный ниже, в настоящее время загружается и выполняет итерацию по каждой строке, но затем, как только он пытается найти find_all, он выдает следующую ошибку: IndexError: список индексов выходит за пределы диапазона.
import requests
from bs4 import BeautifulSoup
import csv
with open('1.csv', "r", newline="") as inFile, open("1output.csv", "w", newline="") as outFile:
next(inFile)
reader = csv.reader(inFile)
writer = csv.writer(outFile)
for row in reader:
subURL = row[0]
# Parse the HTML from the website
URL = 'https://www.example.com/{}'.format(subURL)
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
# find iframe on webpage and get the src of the iframe
iframeDesc = soup.find_all('iframe')[0]
pageDesc = requests.get(iframeDesc['src'])
soupDesc = BeautifulSoup(pageDesc.content, 'html.parser')
# Get Description from iframe Desc
itemDesc = soupDesc.find_all('div', id="div_01")
В этой строке возникает ошибка:
iframeDesc = soup.find_all('iframe')[0]