這個問題在這里已經有了答案: “縮進中制表符和空格的使用不一致” 28個答案 3天前關閉。
代碼 python 有什么問題?
import requests
from bs4 import BeautifulSoup
import argparse
class crtShClass():
def __init__(self,domain):
self.url = "https://crt.sh/?q=%." domain
self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0'}
self.cookies = {}
self.foundURLsList = []
def subdomainScrape(self):
r = requests.get(self.url,headers=self.headers,timeout=10)
soup = BeautifulSoup(r.content,'html.parser')
tableRows = soup.find_all('table')[2].find_all('tr')
for row in tableRows:
try:
subdomain = row.find_all('td')[4].text
subdomain = subdomain.replace("*.","")
if subdomain not in self.foundURLsList:
self.foundURLsList.append(subdomain)
except Exception as e:
pass
def run(self):
self.subdomainScrape()
def printSubdomains(self):
for subdomain in self.foundURLsList:
print(subdomain)
parser = argparse.ArgumentParser()
parser.add_argument("-d","--domain", help="Domain Name; EX: example.com")
args = parser.parse_args()
crtsh = crtShClass(args.domain)
crtsh.run()
crtsh.printSubdomains()
在 python3 的終端中.. 錯誤是:第 22 行 subdomain = subdomain.replace("*.","") TabError: 在縮進中不一致使用制表符和空格
在此處輸入影像描述
在python2 ..錯誤是:
回溯(最后一次呼叫):檔案“certsh.py”,第 2 行,從 bs4 匯入 BeautifulSoup ImportError:沒有名為 bs4 的模塊
在此處輸入影像描述
uj5u.com熱心網友回復:
只需嘗試更正縮進,如下所示:
....
try:
subdomain = row.find_all('td')[4].text
subdomain = subdomain.replace("*.","")
if subdomain not in self.foundURLsList:
self.foundURLsList.append(subdomain)
except Exception as e:
pass
...
當前版本的 bs4 不支持 python 2
Beautiful Soup 對 Python 2 的支持已于 2020 年 12 月 31 日停止:在 Python 2 本身的日落日期之后一年。從現在開始,新的 Beautiful Soup 開發將專門針對 Python 3。Beautiful Soup 4 支持 Python 2 的最終版本是 4.9.3。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/451774.html
