Web Scraping Craiglist

Samuel Odulaja
Posted on Oct 21, 2019

This article will go through how one would scraped data from New York Craigslist .  

Craigslist is an advertisement website that people use to find jobs, housing, items for sale, services, music gigs, etc. The code used to scrape the data can be found on GitHub


Getting the Data

To collect the data BeautifulSoup from bs4, which is a Python library that is used for pulling data from HTML files, was used. The type and length of each item was checked to see if it matched the number of posts per page, which is 120 on Craigslist. The code below shows this process: 

Using the find_all method, shown in the code above. The website was examined, and the tag of each post was found. From the screenshot below it's shown that the parent tag of each posts is <li class = "result-row">.

Using the screenshot above the, the attributes that were extracted for each post were:

  • Time Posted
  • Neighborhoods
  • Number of bedrooms
  • Square Feet
  • URL
  • Price

After running the Beautiful Soup code, a dataframe was created that listed the values. 

The code that was used to create the dataframe is shown below:

Data Analysis

The reason for this analysis was to see what factors into the pricing of Manhattan apartments, and to help people looking for apartments. The below plot shows the distributions of prices in Manhattan. From the plot most of the apartments fall in the $2000-$3000 price range. There also seems to be some outliers around the $9000-12000 range. 

Regression analysis was also done between the Square footage and the Price, to see if there was any correlation between the two variables. From the scatterplot below it seems there is a slight positive correlation. However there seems to be some outliers, so square footage might not be the most reliable factor in determining the price of an apartment. 

So  to determine if square footage was the best indicator for determining the price, a regression plot with the best fit line was plotted. From the below plot it seems that the fit of the line for the two variables is adequate. 


As stated before it seems the best fit line was adequate, and for a deeper look the correlation for the two variables was calculated. 

Correlation matrix for variables

It is not surprising that there is a slightly strong correlation between the number of bedrooms and square footage, since the more bedrooms there are the bigger the apartment should be.  However there doesn't seem to be a strong correlation between price and number of bedrooms, in fact it's pretty weak. 

Further analysis was done regarding the prices by neighborhood. The bar plot shows the average price per neighborhood, and the box plot gives a more in depth analysis, showing the price range for each neighborhood. 

Boxplot of Prices by Neighborhood
Barplot of Prices by Neighborhood


Out of all the neighborhoods Soho was shown to have the largest spread. However further research will need to be done to understand what's happening with Tribeca since it has no whiskers.  Harlem seems to have the lowest average price per apartment. This data can help provide insight for a person looking for a apartment in Manhattan. 

In the future, further data cleaning will be done, and more insight will be done into other variables. Also, further data scraping will be done with the other boroughs. 

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp