Finding the description of a port number using the mediawiki_table_scraper gem

require 'dynarex'
require 'mediawiki_table_scraper'

url = 'https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers'

tables = MediaWikiTableScraper.new(url).to_a
dx = Dynarex.new('ports/entry(port, tcp, udp, description, status)')

# remove additional entries associated with a single port
ports_wellknown = tables.first.uniq {|x| x[:port]}

dx.import ports_wellknown
port = dx.find_by_port '80'
puts port.description
#=> Hypertext Transfer Protocol  (HTTP) [13]

Resources