How can i fix index out of range?

    import requests
from bs4 import BeautifulSoup
import csv
from itertools import zip_longest

result = requests.get("https://wuzzuf.net/search/jobs/?a=hpb%7Cspbg&q=data")
src = result.content
soup = BeautifulSoup(src, "lxml")

Job_title = []
Firm_name = []

Job_titles = soup.find_all("a", {"class":"css-nn640c"})
Firm_names = soup.find_all("a", {"class":"css-17s97q8"})

for i in range(len(Job_titles)):
    Job_title.append(Job_titles[i].text)
    Firm_name.append(Firm_names[i].text)
    Filelist = [Job_title, Firm_name]
    Exported = zip_longest(*Filelist)


with open(r"C:\Users\****\Desktop\python\mydata.csv", "w") as myfile:
    wr = csv.writer(myfile)
    wr.writerow("Job title", "Company name")
    wr.writerows(Exported)

Whats wrong with my code, it keeps generating this error" File "C:\Users****\PycharmProjects\pythonProject\Test1\Scrape.py", line 18, in Firm_name.append(Firm_names[i].text) IndexError: list index out of range



Read more here: https://stackoverflow.com/questions/67012468/how-can-i-fix-index-out-of-range

Content Attribution

This content was originally published by Gigiwan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: