-4

what is wrong in code python ?

import requests
from bs4 import BeautifulSoup
import argparse

class crtShClass():

    def __init__(self,domain):
        self.url = "https://crt.sh/?q=%25."+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()

in terminal by python3.. the error is : line 22 subdomain = subdomain.replace("*.","") TabError: inconsistent use of tabs and spaces in indentation

enter image description here

in python2.. the error is :

Traceback (most recent call last): File "certsh.py", line 2, in from bs4 import BeautifulSoup ImportError: No module named bs4

enter image description here

Ahmed nasr
  • 91
  • 5
  • The error is obvious. Why are you leaving so many spaces on line 22 and 23? Remove them and indent them according to `try` code block. – Abhyuday Vaish Mar 26 '22 at 09:16

1 Answers1

1

Just try to correct indentation like shown below:

....
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
...

Current version of bs4 does not support python 2

Beautiful Soup's support for Python 2 was discontinued on December 31, 2020: one year after the sunset date for Python 2 itself. From this point onward, new Beautiful Soup development will exclusively target Python 3. The final release of Beautiful Soup 4 to support Python 2 was 4.9.3.

gremur
  • 1,645
  • 2
  • 7
  • 20