Skip to content

sillpa-polasani/get-hrefs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

get-hrefs

Build status NPM version XO code style

Get all href urls from an HTML string

Installation

Install get-hrefs using npm:

npm install --save get-hrefs

Usage

Module usage

var getHrefs = require('get-hrefs');

getHrefs(`
	<body>
		<a href="http://example.com">Example</a>
	</body>
`);
// ["http://example.com"]

getHrefs(`
	<head>
		<base href="http://example.com/path1/">
	</head>
	<body>
		<a href="path2/index.html">Example</a>
	</body>
`);
// ["http://example.com/path1/path2/index.html"]

CLI usage

$> get-hrefs --help

Get all href urls from an HTML string

  Usage:
  	get-hrefs <html file>
  	cat <html file> | get-hrefs

  Options:
  	-b, --base-url	Set baseUrl

  Examples:
  	curl -s example.com | get-hrefs

API

getHrefs(html, [options])

Name Type Description
html String The HTML string to extract hrefs from
options Object Optional options

Returns: Array<String>, all unique and normalized hrefs resolved from any provided baseUrl and <base href="..."> in the HTML document.

options.baseUrl

Type: String
Default: ""

The baseUrl to use for relative hrefs. The module also takes <base ...> tags into account.

Related modules

License

MIT © Joakim Carlstein

About

Get all href urls from an HTML string

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%