Home python How to check if there is a site through python

How to check if there is a site through python

Author

Date

Category

The user enters the site name and the program must independently check what this site is:
Suppose the user enters: Google
The program must check what kind of site: google.com or google.ru and so on …
And if this site exists, then open it


Answer 1, Authority 100%

So far, no one who really knows those who really answer, I see this way on the basis of the question, such an outline:

import requests
Domens = ['.ru', '.com', '.rf', '.net', '.org', '.ru.net', '.pro', '.ua',]
DEF Check_Site (Site_Name):
  For Domen in Domens:
    Site = F'Https: // www. {site_name} {Domen} '
    Try:
      Response = Requests.get (Site)
      Print (F'Na site "{site}" can go ')
    Except:
      Print (F'Site "{Site}" does not open ')
Check_Site ('Google')

Result:

to the site "https://www.google.ru" you can go
To the site "https://www.google.com" you can go
Site "https: //www.google.rf" does not open
On the site "https://www.google.net" you can go
To the site "https://www.google.org" you can go
Site "https://www.google.ru.net" does not open
Site "https://www.google.pro" does not open
To the site "https://www.google.ua" you can go

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions