How can i fix index out of range?

  python, scrape
    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****Desktoppythonmydata.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****PycharmProjectspythonProjectTest1Scrape.py", line 18, in
Firm_name.append(Firm_names[i].text)
IndexError: list index out of range

Source: Python Questions

LEAVE A COMMENT