Code Monkey home page Code Monkey logo

get-hrefs's Introduction

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

const 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
    <all other flags are passed to normalize-url>

  Examples:
    curl -s example.com | get-hrefs
    echo '<a href="http://www.example.com">Link</a>' | get-hrefs --strip-w-w-w

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.

options.allowedProtocols

Type: Object
Default: {"http": true, "https": true}

Specifies which protocols to allow by setting their respective key (the protocol name without ":") in allowedProtocols to true (or to false to disable one of the defaults), e.g. allowedProtocols: {tel: true, http: false} will return only found URLs with the protocols tel: or https:.

options.<any>

All other options are passed to normalize-url. See its options for alternatives.

Related modules

License

MIT © Joakim Carlstein

get-hrefs's People

Contributors

joakimbeng avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

get-hrefs's Issues

node-red-contrib-get-hrefs 2.1.0 issue with prototype pollution ?

Hi there I wanted you use the get href node but installing I got some errors around the use of loadash which has been updated to fix their bug. Not sure what's required to fix the node-red-contrib-get-hrefs

I think its only a minor security issue but thought I'd report it.
https://www.npmjs.com/advisories/577

npm audit

                   === npm audit security report ===


                             Manual Review
         Some vulnerabilities require your attention to resolve

      Visit https://go.npm.me/audit-guide for additional guidance

Low Prototype Pollution

Package lodash

Patched in >=4.17.5

Dependency of node-red-contrib-get-hrefs

Path node-red-contrib-get-hrefs > get-hrefs > cheerio > lodash

More info https://nodesecurity.io/advisories/577

found 1 low severity vulnerability in 404 scanned packages
1 vulnerability requires manual review. See the full report for details.

Pass options to normalizeurl

get-hrefs by default is stripping of www from the urls by default.
By passing an option 'stripWWW' to normalizeUrl we can either remove www from the url or leave it as it is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.