Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcff9e58

Browse files
committed
added getting domain info tutorial
1 parent3206128 commitcff9e58

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
8181
-[How to Use Proxies to Anonymize your Browsing and Scraping using Python](https://www.thepythoncode.com/article/using-proxies-using-requests-in-python). ([code](web-scraping/using-proxies))
8282
-[How to Extract Script and CSS Files from Web Pages in Python](https://www.thepythoncode.com/article/extract-web-page-script-and-css-files-in-python). ([code](web-scraping/webpage-js-css-extractor))
8383
-[How to Extract and Submit Web Forms from a URL using Python](https://www.thepythoncode.com/article/extracting-and-submitting-web-page-forms-in-python). ([code](web-scraping/extract-and-fill-forms))
84+
-[How to Get Domain Name Information in Python](https://www.thepythoncode.com/article/extracting-domain-name-information-in-python). ([code](web-scraping/get-domain-info))
8485

8586
-###[Python Standard Library](https://www.thepythoncode.com/topic/python-standard-library)
8687
-[How to Transfer Files in the Network using Sockets in Python](https://www.thepythoncode.com/article/send-receive-files-using-sockets-python). ([code](general/transfer-files/))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[How to Get Domain Name Information in Python](https://www.thepythoncode.com/article/extracting-domain-name-information-in-python)
2+
To run this:
3+
-`pip3 install -r requirements.txt`
4+
- Use`validate_domains.py` code to validate domains
5+
- Use`get_domain_info.py` code to get various domain information from WHOIS
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
importwhois
2+
fromvalidate_domainsimportis_registered
3+
4+
domain_name="google.com"
5+
ifis_registered(domain_name):
6+
whois_info=whois.whois(domain_name)
7+
# print the registrar
8+
print("Domain registrar:",whois_info.registrar)
9+
# print the WHOIS server
10+
print("WHOIS server:",whois_info.whois_server)
11+
# get the creation time
12+
print("Domain creation date:",whois_info.creation_date)
13+
# get expiration date
14+
print("Expiration date:",whois_info.expiration_date)
15+
# print all other info
16+
print(whois_info)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-whois
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
importwhois# pip install python-whois
2+
3+
defis_registered(domain_name):
4+
"""
5+
A function that returns a boolean indicating
6+
whether a `domain_name` is registered
7+
"""
8+
try:
9+
w=whois.whois(domain_name)
10+
exceptException:
11+
returnFalse
12+
else:
13+
returnbool(w.domain_name)
14+
15+
16+
if__name__=="__main__":
17+
# list of registered & non registered domains to test our function
18+
domains= [
19+
"thepythoncode.com",
20+
"google.com",
21+
"github.com",
22+
"unknownrandomdomain.com",
23+
"notregistered.co"
24+
]
25+
# iterate over domains
26+
fordomainindomains:
27+
print(domain,"is registered"ifis_registered(domain)else"is not registered")
28+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp