You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/siddhant-vij/HTML-Link-Parser

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/siddhant-vij/HTML-Link-Parser

v0.0.0-20240409074047-f597c94cabe7
Source
Go
Version published
Created
Source

Gophercises Exercise Details:

In this exercise your goal is 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 you should return a data structure that includes the href.

Links will be nested in different HTML elements, and it is very possible that you 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",
}

Once you have a working program, try to write some tests for it to practice using the testing package in go.


Technical Notes

  • Use the x/net/html package. Package html implements an HTML5-compliant tokenizer and parser.
  • Ignore nested links. Eg with following HTML:
    <a href="#">
    Something here <a href="/dog">nested dog link</a>
    </a>
    
    It is okay if your code returns only the outside link - for the purposes of this exercise.
    Include the nested links as well in the output.
  • Test the code with example files included in the project repository. Improve your tests and edge-case coverage. Add Examples and Documentation for the code. Run the following in this order, using go tooling:
    • tests
      • go test
    • coverage
      • go test -cover
      • go test -coverprofile coverage.out
    • coverage shown in web browser
      • go tool cover -html=coverage.out
    • examples shown in documentation in a web browser
      • godoc -http=:8080

FAQs

Package last updated on 09 Apr 2024

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.