Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

Add sflib extractUrls function to extract all URLs from a string

Brendan Colesb74266f6dee7
diff --git a/sflib.py b/sflib.py
index eedc9106..c8da973b 100644
--- a/sflib.py
+++ b/sflib.py
@@ -15,6 +15,7 @@ from stem import Signal
from stem.control import Controller
import inspect
import hashlib
+import html
import urllib.request, urllib.parse, urllib.error
import json
import re
@@ -1337,6 +1338,11 @@ class SpiderFoot:
return ret
+ # Extract all URLs from a string
+ # https://tools.ietf.org/html/rfc3986#section-3.3
+ def extractUrls(self, content):
+ return re.findall("(https?://[a-zA-Z0-9-\.:]+/[\-\._~!\$&'\(\)\*\+\,\;=:@/a-zA-Z0-9]*)", html.unescape(content))
+
# Find all URLs within the supplied content. This does not fetch any URLs!
# A dictionary will be returned, where each link will have the keys
# 'source': The URL where the link was obtained from