Error when using bs4 in python: Did you call find_all() when you meant to call find()?
Question:
File "/home/x/Desktop/Python Programs/Web Scraping tutorial/ccrealweb.py", line 8, in <module> company_name = jobs.find('a', class_ = 'gtmJobListingPostedBy').a.text
File "/usr/lib/python3/dist-packages/bs4/element.py", line 2253, in __getattr__ raise
AttributeError( AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
When trying to run some basic web scraping code,I get these errors. I’ve had a look around at other forums, and haven’t seen something like my particular code (or at least that I can understand). Please help, as I am thoroughly clueless right now.
from bs4 import BeautifulSoup
import requests
html_text = requests.get('https://www.reed.co.uk/jobs/python-jobs').text
soup = BeautifulSoup(html_text, 'lxml')
jobs = soup.find_all('article', class_ = 'job-result-card')
for job in jobs:
company_name = jobs.find('a', class_ = 'gtmJobListingPostedBy').text
skills = jobs.find('p', class_ = 'job-result-description__details').text
published_date = jobs.find('div', class_ = 'job-result-heading__posted-by').text.strip()
print('Company name:', company_name)
print('Skills:', skills)
print(published_date, 'n')
Answers:
you do
for job in jobs
then you have to do job.find and not jobs.find
Your code works very well afterwards.
Company name: Marshall Wolfe
Skills:
Python software Engineer - Software Developer Our client a growing technology consultancy based in Suffolk, is recruiting the services of a Software Engineer on a permanent basis. This role would suit either a graduate level developer looking for their...
30 November 2022 by Marshall Wolfe
....
File "/home/x/Desktop/Python Programs/Web Scraping tutorial/ccrealweb.py", line 8, in <module> company_name = jobs.find('a', class_ = 'gtmJobListingPostedBy').a.text
File "/usr/lib/python3/dist-packages/bs4/element.py", line 2253, in __getattr__ raise
AttributeError( AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
When trying to run some basic web scraping code,I get these errors. I’ve had a look around at other forums, and haven’t seen something like my particular code (or at least that I can understand). Please help, as I am thoroughly clueless right now.
from bs4 import BeautifulSoup
import requests
html_text = requests.get('https://www.reed.co.uk/jobs/python-jobs').text
soup = BeautifulSoup(html_text, 'lxml')
jobs = soup.find_all('article', class_ = 'job-result-card')
for job in jobs:
company_name = jobs.find('a', class_ = 'gtmJobListingPostedBy').text
skills = jobs.find('p', class_ = 'job-result-description__details').text
published_date = jobs.find('div', class_ = 'job-result-heading__posted-by').text.strip()
print('Company name:', company_name)
print('Skills:', skills)
print(published_date, 'n')
you do
for job in jobs
then you have to do job.find and not jobs.find
Your code works very well afterwards.
Company name: Marshall Wolfe
Skills:
Python software Engineer - Software Developer Our client a growing technology consultancy based in Suffolk, is recruiting the services of a Software Engineer on a permanent basis. This role would suit either a graduate level developer looking for their...
30 November 2022 by Marshall Wolfe
....