Tuesday, September 17, 2024

Find all links on a webpage

import requests, re

url = "https://medium.com/@binoythomas1108/understanding-classification-metrics-through-fairy-tales-5434213aa441"

website = requests.get(url)

html = website.text # read html

links = re.findall('"((http|ftp)s?://.*?)"', html) # re.findall grabs links

for i, link in enumerate(links): # output links

  print(i+1, link[0], "\n")

No comments:

Post a Comment