python whois
时间: 2023-07-14 17:57:12 浏览: 53
`python-whois` 是一个用于解析 WHOIS 数据库记录的 Python 包。它可以用来获取域名的注册信息,如注册人、注册机构、注册日期、过期日期等。你可以使用 `pip install python-whois` 命令来安装它。在 Python 中使用 `whois.whois(domain_name)` 函数来查询域名的 WHOIS 信息。其中 `domain_name` 是要查询的域名。例如:`whois.whois('google.com')`。
相关问题
Python编写whois
以下是使用Python编写whois的示例代码:
```python
import requests
from bs4 import BeautifulSoup
def get_whois_info(domain):
url = "http://site.ip138.com/{}/whois.htm".format(domain)
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
whois_info = soup.find('div', {'class': 'whoisinfo'})
return whois_info.text
# 示例
print(get_whois_info('baidu.com'))
```
该代码使用requests库向ip138网站发送请求,获取whois信息。然后使用BeautifulSoup库解析HTML页面,提取whois信息并返回。
python安装whois库
您可以通过以下命令在命令行中安装whois库:
```
pip install python-whois
```
如果您使用的是Anaconda环境,可以使用以下命令:
```
conda install -c conda-forge python-whois
```
安装完成后,您可以在Python代码中使用以下语句导入whois库:
```python
import whois
```