🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

github.com/ahmadateya/learning-Go-by-projects/html-link-parser

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ahmadateya/learning-Go-by-projects/html-link-parser

v0.0.0-20211209134444-0c3b10c68379
Version published
Created

the goal of this exercise is to create a package that makes it easy to parse an HTML file and extract all of the links (<a href="">...</a> tags). For each extracted link the package should return a data structure that includes both the href, as well as the text inside the link. Any HTML inside of the link can be stripped out, along with any extra whitespace including newlines, back-to-back spaces, etc.

Links will be nested in different HTML elements, and it is very possible that we will have to deal with HTML similar to code below.

<a href="/dog">
  <span>Something in a span</span>
  Text not in a span
  <b>Bold text!</b>
</a>

In situations like these we want to get output that looks roughly like:

Link{
  Href: "/dog",
  Text: "Something in a span Text not in a span Bold text!",
}

Packages I Used:

  • io
  • golang.org/x/net/html

FAQs

Package last updated on 09 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts