Is there a way to more accurately search for a class with BeautifulSoup

Viewed 34

I'm trying to scrape this job site for a specific job title but I keep getting this error message.

Traceback (most recent call last):
  File "/home/malachi/Documents/python_projects/Practice/Jobsearcher.py", line 7, in <module>
    print(results.prettify())
AttributeError: 'NoneType' object has no attribute 'prettify'

I've run this same code on other websites with different class names and I got results but when I run it on the website I need it says that the class doesn't exist

from bs4 import BeautifulSoup
page =requests.get("https://careers.united.com/job-search-results/")
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(class_ = "jobTitle")
print(results)
print(results.prettify())```
1 Answers

I have changed this line of code:

results = soup.find(class_ = "jobTitle")

to these two lines of code. I have tested them and they work for me.

results = soup.find('a', attrs={'id': "job-result0"})
results = results.string

I use Google Chrome. It has the free extension ChroPath, which makes it super easy to identify selectors. I just right click on text in a browser and select Inspect, sometimes twice, and the correct HTML tag is highlighted.

Related