2

我正在做一个项目,我应该使用 python 查找批量域的域年龄。在 python 中,我发现了一个名为 python-whois 的库,它可以非常精确地处理少量域,最多 8 个域,之后它会给出一些错误,比如违反使用条款,因为该服务不是用于自动化的。我写了以下代码

import datetime
import pandas as pd
sheet=pd.read_csv('Phishing_url.csv')
x=sheet['url']
def url_age(url):
    details=whois.whois(url)
    try:
        try:
            if(len(details.creation_date)>1):
                createdate=details.creation_date[0]
            
        except:
            createdate=details.creation_date
            print(createdate)
        finally:
            today=datetime.datetime.today()
            day=today.day-createdate.day
            month=today.month-createdate.month
            year=today.year-createdate.year
            age=(year*365)+(month*30)+day
            age=age/365
            print(age)
    except:
        print("error fetching")
        
        
    return
    
    #driver
     for i in x:
            url_age(i)

抛出给定的输出和错误

0.13150684931506848
0.13150684931506848
6.328767123287672
6.328767123287672
2020-02-23 20:09:08
0.3835616438356164
Error trying to connect to socket: closing socket
None
error fetching
2020-02-24 10:23:59
0.38082191780821917
0.3780821917808219
2020-02-25 16:50:21
0.3780821917808219
2020-02-25 16:50:21
0.3780821917808219

---------------------------------------------------------------------------
PywhoisError                              Traceback (most recent call last)
<ipython-input-19-b12c93468373> in <module>
      1 for i in x:
----> 2     url_age1(i)

<ipython-input-17-d02272ed899c> in url_age1(url)
      1 def url_age1(url):
----> 2     details=whois.whois(url)
      3     try:
      4         try:
      5             if(len(details.creation_date)>1):

C:\ProgramData\Anaconda3\lib\site-packages\whois\__init__.py in whois(url, command, flags)
     42         nic_client = NICClient()
     43         text = nic_client.whois_lookup(None, domain.encode('idna'), flags)
---> 44     return WhoisEntry.load(domain, text)
     45 
     46 

C:\ProgramData\Anaconda3\lib\site-packages\whois\parser.py in load(domain, text)
    186 
    187         if domain.endswith('.com'):
--> 188             return WhoisCom(domain, text)
    189         elif domain.endswith('.net'):
    190             return WhoisNet(domain, text)

C:\ProgramData\Anaconda3\lib\site-packages\whois\parser.py in __init__(self, domain, text)
    399     def __init__(self, domain, text):
    400         if 'No match for "' in text:
--> 401             raise PywhoisError(text)
    402         else:
    403             WhoisEntry.__init__(self, domain, text)

PywhoisError: No match for "COM&AMP;EMAIL=ADMIN@EXAMPLE.COM".
>>> Last update of whois database: 2020-07-13T07:14:46Z <<<

NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar.  Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.

TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability.  VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars

错误可概括为“您无权通过使用高容量和自动化的电子流程访问或查询我们的 Whois 数据库,除非注册域名或修改现有注册的合理必要”

谁能帮我做同样的程序,或者可以建议替代程序来查找域的年龄。

4

0 回答 0