Please what's wrong in this code (Webscrapping - BeautifulSoup)

47 views Asked by At

``from bs4 import BeautifulSoup import requests`

html_page = requests. Get[jooble]('https://ng.jooble.org/SearchResult?ukw=ict').text
soup = BeautifulSoup(html_page, 'lxml')
job_card = soup.find_all('article', attrs= {"data-test-name":"_jobCard","class_":"FxQpvm yKsady"},             limit=10)

job _title =  job _card .find('h2',  attrs={"class":"_15V35X"})
job _ Requirment = job _card .find('div', attrs={"class":"_9jGwm1"})
company = job_card.find('p', attrs={"class":"Ya0gV9"})
post_date = job_card.find('div', class_ = 'caption  e0VAhp')
job_link = job_card.header.h2.a['href']

print(' ')
print(f'JOB TITLE: {job_title}')
print(f'COMPANY NAME: {company}')
print(f'JOB REQUIREMENT: {job_Requirment} (Read More...)') 
print(f'POSTED: {post_date}')
print(f'MORE INFO: {job_link}')
print(' ')

from bs4 import BeautifulSoup import requests

This code is meant to give give me a list of the print line, but

Here is what i get in response: Traceback (most recent call last): File "C:\Users\Samuel Oluwapelumi\Desktop\cs50web\jobs.py", line 8, in job_title = job_card.find('h2', attrs={"class":"_15V35X"}) ^^^^^^^^^^^^^ File "C:\Users\Samuel Oluwapelumi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\bs4\element.py", line 2428, 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()?`

1

There are 1 answers

0
yashaswi k On

@samuel please follow below code, i have made changes to get the job title, please follow same for other categories

from bs4 import BeautifulSoup 
import requests

html_page = requests.get('https://ng.jooble.org/SearchResult?ukw=ict')
soup = BeautifulSoup(html_page.content, 'lxml')

job_title =  soup.find_all('h2',attrs={"class":"_15V35X"})
job_titlelist1=[]
for line in job_title:
  job_titlelist1.append(line.text)

print(f'JOB TITLE: {job_titlelist1}')

output:

 JOB TITLE: ['ICT Officer', 'ICT Coordinator', 'ICT Teacher', 'ICT/Tech Support Staff', 'Technician (ICT)', 'Senior ICT Specialist at Palladium Group', 'ICT Teacher', 'ICT Teacher', 'Computer (ICT) Teacher', 'Senior ICT Specialist at Palladium', 'Ict Professional Urgently Needed', 'ICT Head', 'ICT Technical Assistant at the Norwegian Refugee Council (NRC)', 'ICT Head at Walex Biz Nigeria Limited', 'ICT Manager at Ascentech Services Limited', 'An Ict Professional Urgently Needed', 'Credit Officers, ICT Officers and Marketing Officers at Reputable Microfinance Bank', 'ICT Officer at Engine Lubricant Manufacturing Company', 'ICT Technical Assistant Nigeria Jos, Abuja', 'ICT and Coding Instructor at Proxynet Communication']