0

I would like to look get the host name using requests repository in python. I tried to do this like that:

pprint(requests.get("https://www.facebook.com/").headers['domain'])

but it doesn't work. If it is possible in other repository I would be grateful for any answer.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

Based on Regular Expression - Extract subdomain & domain

import requests
import re

p = re.compile("^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/?\n]+)")

r = requests.get("https://www.google.com/")
domain = p.match(r.url).group(1)
print(domain)
Mathieu Rollet
  • 2,016
  • 2
  • 18
  • 31