HTML Scraping: Extracting Specific Text and Tags

Scrape specified text from a webpage and print text from the first 10 `<a>` tags.

Gain practical experience in web scraping by tackling two coding challenges designed to extract specific text and HTML tag data. Strengthen your programming capabilities by practicing targeted scraping techniques.

Key Insights

  • The first coding challenge requires participants to programmatically locate and extract specific text content from a provided webpage.
  • The second challenge involves retrieving and printing text from the first 10 anchor (a) tags on a page, emphasizing precision to avoid excessive data (hundreds of tags).
  • Participants apply hands-on web scraping methods, reinforcing their skills in targeted HTML data extraction practices.

Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.

Let's give you a couple challenges here. Here the first challenge is finding this text somewhere on that page that we've given you and scrape it and print out the text of the tag that contains it, which will actually be just this text. Print it out, scrape it programmatically, get it into here.

Challenge two is find all eight tags on the page and print the text for the first 10. I want to stress this because if you try to print all of them it's going to be hundreds, hundreds and hundreds and hundreds. So just print the first 10 a tags on from the page, the text from those first 10.

Data Science Certificate: Live & Hands-on, In NYC or Online, 0% Financing, 1-on-1 Mentoring, Free Retake, Job Prep. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

All right, those are your two challenges. I'll let you folks go at it.

Colin Jaffe

Colin Jaffe is a programmer, writer, and teacher with a passion for creative code, customizable computing environments, and simple puns. He loves teaching code, from the fundamentals of algorithmic thinking to the business logic and user flow of application building—he particularly enjoys teaching JavaScript, Python, API design, and front-end frameworks.

Colin has taught code to a diverse group of students since learning to code himself, including young men of color at All-Star Code, elementary school kids at The Coding Space, and marginalized groups at Pursuit. He also works as an instructor for Noble Desktop, where he teaches classes in the Full-Stack Web Development Certificate and the Data Science & AI Certificate.

Colin lives in Brooklyn with his wife, two kids, and many intricate board games.

More articles by Colin Jaffe

How to Learn Data Science

Master data science with hands-on training. Data science is a field that focuses on creating and improving tools to clean and analyze large amounts of raw data.

Yelp Facebook LinkedIn YouTube Twitter Instagram