URL Extraction Function

  • Share this:

Code introduction


This function extracts all possible URL links from the given text.


Technology Stack : re module (regular expression library), os module (access to the operating system), json module (JSON data processing), sys module (system access), time module (time access), random module (random number access)

Code Type : String Handling Function

Code Difficulty : Intermediate


                
                    
import os
import re
import json
import sys
import time
import random

def extract_links(text):
    links = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', text)
    return links