-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeautifulSoup.py
38 lines (29 loc) · 1.16 KB
/
BeautifulSoup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
from bs4 import BeautifulSoup
URL = "https://realpython.github.io/fake-jobs/"
page = requests.get(URL)
#print(page.text)
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(id="ResultsContainer")
#print(results.prettify())
job_elements = results.find_all("div", class_="card-content")
# for job_element in job_elements:
# print(job_element, end="\n" * 2)
# for job_element in job_elements:
# title_element = job_element.find("h2", class_="title")
# company_element = job_element.find("h3", class_="company")
# location_element = job_element.find("p", class_="location")
# print(title_element)
# print(company_element)
# print(location_element)
# print()
for job_element in job_elements:
title_element = job_element.find("h2", class_="title")
company_element = job_element.find("h3", class_="company")
location_element = job_element.find("p", class_="location")
print(title_element.text.strip())
print(company_element.text.strip())
print(location_element.text.strip())
print()
python_jobs = results.find_all("h2", string="Python")
print(python_jobs)