Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Applied Data Science with Python and Jupyter

You're reading from   Applied Data Science with Python and Jupyter Use powerful industry-standard tools to unlock new, actionable insights from your data

Arrow left icon
Product type Paperback
Published in Oct 2018
Publisher
ISBN-13 9781789958171
Length 192 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alex Galea Alex Galea
Author Profile Icon Alex Galea
Alex Galea
Arrow right icon
View More author details
Toc

Chapter 3: Web Scraping and Interactive Visualizations

Activity 3: Web Scraping with Jupyter Notebooks

  1. For this page, the data can be scraped using the following code snippet:
    data = []
    for i, row in enumerate(soup.find_all('tr')): row_data = row.find_all('td')
    try:
    d1, d2, d3 = row_data[1], row_data[5], row_data[6] d1 = d1.find('a').text
    d2 = float(d2.text)
    d3 = d3.find_all('span')[1].text.replace('+', '') data.append([d1, d2, d3])
    except:
    print('Ignoring row {}'.format(i)
  2. In the lesson-3-workbook.ipynb Jupyter Notebook, scroll to Activity A: Web scraping with Python.
  3. Set the url variable and load an IFrame of our page in the notebook by running the following code:
    url = 'http://www.worldometers.info/world-population/ population-by-country/'
    IFrame(url, height=300, width=800)

    The page should load in the notebook. Scrolling down, we can see the Countries in the world by population heading and...

lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime