Python Forum

Full Version: My first Web Scraping project
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, recently, I have been learning web scraping with tutorials and videos and other things like that. Here's my first go at a simple project that helps in displaying software developer jobs available in New York from the Monster.com site
import requests
from bs4 import BeautifulSoup

URL = "https://www.monster.com/jobs/search/?q=Software-Developer&where=NewYork"
page = requests.get(URL)

soup = BeautifulSoup(page.content, 'html.parser')

results = soup.find(id='ResultsContainer')


job_elements = results.find_all('section', class_='card-content')

for job_element in job_elements:
    title_element = job_element.find('h2', class_='title')
    company_element = job_element.find('div', class_='company')
    location_element = job_element.find('div', class_='location')
    if None in (title_element, company_element, location_element):
        continue
    print(title_element.text.strip())
    print(company_element.text.strip())
    print(location_element.text.strip())
    print()
Any feedback would be appreciated!
(And yes, I had to take some help for this but please - I'm a beginner in this topic)
Pretty clean compared to others i have seen. Web scraping can get messy quickly. So it is important to keep it clean and organized.
Well, I had learnt that not keeping it messy was one of the most important steps in web scrapping, so I did the best I could
elements = (title_element, company_element, location_element)
if all(elements):
    for element in elements:
        print(element.text.strip())
    print()
the part where you search for each element can also be shortened with a loop if you have a container type with what you search for
Thanks for your suggestion @buran!