I'm not having any luck with the other question that is posted on this website. My goal for this program is to scrape job postings from Indeed.com. I'm running into an attribute error. I don't know why I'm receiving this error because I'm making sure the tags match between the HTML and Python. Can anyone help me with this?
Code:
import urllib.request as urllib
from bs4 import BeautifulSoup
import csv
# empty array for results
results = []
# initialize the Indeed URL to url string
url = 'https://www.indeed.com/jobs?q=software+developer&l=Phoenix,+AZ&jt=fulltime&explvl=entry_level'
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
results = soup.find_all('div', attrs={'class': 'jobsearch-SerpJobCard'})
for i in results:
title = i.find('div', attrs={"class":"title"})
print('\ntitle:', title.text.strip())
salary = i.find('span', attrs={"class":"salaryText"})
print('salary:', salary.text.strip())
company = i.find('span', attrs={"class":"company"})
print('company:', company.text.strip())
Error log:
Traceback (most recent call last): File "c:/Users/Scott/Desktop/code/ScrapingIndeed/index.py", line 16, in print('salary:', salary.text.strip())
Scott@DESKTOP-MS37V5T MINGW64 ~/Desktop/code
$ AttributeError: 'NoneType' object has no attribute 'text'
Code from indeed.com I'm trying to scrape:
<span class="salaryText">
$15 - $30 an hour</span>