Reputation: 4842
I am trying to read the following:
My goal is to read every job title from this page - https://www.cvbankas.lt/?miestas=Vilnius&padalinys%5B%5D=&keyw=python
What I've tried:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.cvbankas.lt/?miestas=Vilnius&padalinys%5B%5D=&keyw=python'
page = requests.get(URL).text
soup = BeautifulSoup(page, 'html.parser')
results = soup.find(id='ResultsContainer')
# Look for Python jobs
python_jobs = results.find_all("div", string=lambda t: "python" in t.lower())
for p_job in python_jobs:
link = p_job.find("h3")["href"]
print(p_job.text.strip())
print(f"Apply here: {link}\n")
But I get the following error:
AttributeError: 'NoneType' object has no attribute 'find_all'
How can I read all the titles?
Upvotes: 2
Views: 3146
Reputation: 494
Checkout my codes:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.cvbankas.lt/?miestas=Vilnius&padalinys%5B%5D=&keyw=python'
page = requests.get(URL).text
soup = BeautifulSoup(page, 'html.parser')
h3_tags = soup.findAll("h3", {"class": "list_h3"})
for x in h3_tags:
if "Python" in x.text:
print(x.text)
print(x.find_parent('a')['href'])
print()
And The output are:
Senior Python Developer
https://www.cvbankas.lt/senior-python-developer-vilniuje/1-6719819
Full Stack Engineer (React + Python)
https://www.cvbankas.lt/full-stack-engineer-react-python-vilniuje/1-6665723
Python programuotojas (Mid-Senior)
https://www.cvbankas.lt/python-programuotojas-mid-senior-vilniuje/1-6693547
Python Developer
https://www.cvbankas.lt/python-developer-vilniuje/1-6604883
Upvotes: 0
Reputation: 195408
Problem is, there isn't any tag with id="ResultsContainer"
. You can search all <h3>
tags with text Python and then find parent <a>
tag for an url:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.cvbankas.lt/?miestas=Vilnius&padalinys%5B%5D=&keyw=python'
page = requests.get(URL).text
soup = BeautifulSoup(page, 'html.parser')
results = soup.find_all('h3', text=lambda t: 'python' in t.lower())
for r in results:
print(r.text)
print(r.find_parent('a')['href'])
print('-' * 80)
Prints:
Senior Python Developer
https://www.cvbankas.lt/senior-python-developer-vilniuje/1-6719819
--------------------------------------------------------------------------------
Full Stack Engineer (React + Python)
https://www.cvbankas.lt/full-stack-engineer-react-python-vilniuje/1-6665723
--------------------------------------------------------------------------------
Python programuotojas (Mid-Senior)
https://www.cvbankas.lt/python-programuotojas-mid-senior-vilniuje/1-6693547
--------------------------------------------------------------------------------
Python Developer
https://www.cvbankas.lt/python-developer-vilniuje/1-6604883
--------------------------------------------------------------------------------
Upvotes: 2
Reputation: 1143
Replace your code with below code:
import requests
from lxml import etree
from bs4 import BeautifulSoup
URL = 'https://www.cvbankas.lt/?miestas=Vilnius&padalinys%5B%5D=&keyw=python'
page = requests.get(URL).text
soup = BeautifulSoup(page, 'html.parser')
dom = etree.HTML(str(soup))
elements = dom.xpath('//h3[@class="list_h3"]')
for element in elements:
print(element.text)
Upvotes: -1
Reputation: 12672
Your problem is there is no element has a id "ResultsContainer"
.
But refer to the struct of the page, You could use css selector
to get all the information directly:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.cvbankas.lt/?miestas=Vilnius&padalinys%5B%5D=&keyw=python'
page = requests.get(URL).text
soup = BeautifulSoup(page, 'html.parser')
results = soup.select("div.list_cell > .list_h3")
for i in results:
print(i.text)
Result:
Data Engineer
Data Analyst
VYRESNYSIS INŽINIERIUS STRATEGIJOS IR TYRIMŲ SKYRIUJE
Senior Python Developer
Full Stack Engineer (React + Python)
DevOps Engineer
Linux Systems Automation Engineer
Big Data Developer
Big Data Devops Engineer
Python programuotojas (Mid-Senior)
DATA SCIENTIST
DEVOPS INŽINIERIAUS (e-commerce platformos produktų optimizavimas užsienio rinkoms)
LINUX Sistemų administratorius (-ė)
QA engineer
Blockchain Developer
Backend Software Engineer
FW/HW Quality Assurance Engineer
Software developer in Test
Python Developer
Senior Backend Engineer
Upvotes: 1
Reputation: 397
This method: soup.find(id='ResultsContainer')
found no element matching the criteria, and therefore returned None
.
In this line: python_jobs = results.find_all("div", string=lambda t: "python" in t.lower())
, the value of results
is None
.
None.find_all
does not exist. (AttributeError: 'NoneType' object has no attribute 'find_all'
)
Upvotes: 0