Let's Scrape the Skyscrapers using Scrapy

Avatar
Posted on Nov 10, 2016
Contributed by Conred Wang. He is currently in the NYC Data Science Academy 12 week full time Data Science Bootcamp program taking place between September 26th to December 23rd, 2016. This post is based on his third class project - Web Scraping Project (due on the 7th week of the program).

 

 

 

The Skyscraper Center publishes various types of information about the world's skyscrapers.

The Skyscraper Center

For example, the 100 Tallest Completed Buildings in the World by Height to Architectural Top :

Main Page of 100 Tallest Completed Buildings in the World by Height to Architectural Top.

The main page even includes a downloadable PDF.  However, some data, like year the skyscrapers were Proposed and Construction Start, is only available in secondary pages:

Secondary Page of 100 Tallest Completed Buildings in the World by Height to Architectural Top..

 

 

Scrapy

In order to obtain all the data we needed from the main and all secondary web pages, we used Scrapy.

An open source and collaborative framework for extracting the data you need from websites.  In a fast, simple, yet extensible way.

 

 

 

 

 

 

.


 

 

cw-scrapy-cn

ct cc country ct cc country ct cc country
21 AE Arab Emirates 01 AU Australia 45 CN China
01 GB United Kingdom 01 KR South Korea 01 KW Kuwait 
03 MY Malaysia 03 RU Russia 02 SA Saudi Arabia
02 TH Thailand 02 TW Taiwan 17 US USA
01 VN Vietnam

 

Statistics about these 100 skyscrapers:

<Usages>

  • 40 are multipurpose
  • 74 are used for office.
  • 43 are used for hotel.
  • 29 are used for residential.
  • 2 are used for retail.

<Totals>

  • 7,758 floors.
  • 118,653 feet.

<Time>

  • 46 do not have Proposed Year listed.
  • 3 do not have Construction Start Year listed.
  • From Proposed To Construction Start:
    • Cannot compute 46.
    • Shortest took 0 year.
    • Longest took 9 years.
  • From Construction Start To Complete:
    • Cannot compute 3.
    • Shortest took 1 year.
    • Longest took 11 years.

Q : One year to build a skyscraper!  Really?

A : No kidding.  There are actually 2 skyscrapers:

cw-scrape-blgempste  

https://nycdsa-blog-files.s3.us-east-2.amazonaws.com/2016/11/cw.scrape.blgEmpSte.jpg


 

About using Scrapy

Scrapy is really easy and simple.

As depicted in the "A dataflow overview" diagram (below, which can be found at The ITC Prog Blog), we only need to write 3 short Python scripts ("items.py", "pipelines.py" and "skyscraper_spider.py"), and Scrapy did all the data extraction for us from the Skyscraper Center web pages:

cw-scrapy-dataflow

We included all 3 Python scripts below.

It is worth to mentioning that:

  • "scrapy shell <url>" and Google's Chrome inspect are the two indispensable tools when web scraping with Scrapy.
  • Although we love Scrapy, it is not perfect yet. For example, Scrapy will not tell you your Python code indentation is improper.
  • With UTF-8 encoding, the str function over text with unicode (for example, "u2026", horizontal ellipsis) will cause an exception.  Instead,  [<object>.encode('ascii','ignore')] can be used.  You can find an example on line 21 of "pipelines.py".
1. items.py

https://gist.github.com/conredwang/d5622167d39a1de2214d3a48aa285c1f

2. pipelines.py

https://gist.github.com/conredwang/a49b7d9e52b4444e3fe2c69ba5b72556

3. skyscraper_spider.py

https://gist.github.com/conredwang/d086bc048b74104617e604dbb66f4e13

(end)

About Author

Avatar

Conred

As a software engineer, scrum master and project management professional, Conred Wang believes in, "Worry less, smile more. Don't regret, just learn and grow.", which motivated him to study at NYCDSA and become a data scientist. His exposure...
View all posts by Conred >

Leave a Comment

Avatar
reverse phone lookup January 24, 2017
411 reverse phone lookup actual free reverse phone lookup free reverse phone lookup with name free results

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 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