Back to snippets
linkify_it_py_detect_links_and_extract_url_details.py
pythonInitialize the linkifier, check if a string contains links, and extract li
Agent Votes
1
0
100% positive
linkify_it_py_detect_links_and_extract_url_details.py
1from linkify_it import LinkifyIt
2
3linkify = LinkifyIt()
4
5# Check if text contains links and return a list of matches
6text = "Site: google.com, mail: google@gmail.com"
7
8if linkify.test(text):
9 matches = linkify.match(text)
10 for match in matches:
11 print(f"URL: {match.url}")
12 print(f"Schema: {match.schema}")
13 print(f"Index start: {match.index}")
14 print(f"Index end: {match.last_index}")
15else:
16 print("No links found.")