# -*- coding: utf-8 -*- import requests class UrlAttack(): headers = {'Upgrade-Insecure-Requests': "1", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Accept-Encoding': "gzip, deflate, br", 'Accept-Language': "en-US,en;q=0.5", 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Host': 'www.idealista.com', 'Pragma': 'no-cache', 'user-agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0'} timeout = 20 def __init__(self, url): self.url = url self.success = None self.has_been_attacked = False def attack(self): self.has_been_attacked = True try: self.response = requests.get(self.url, headers = self.headers, timeout = self.timeout) if self.response.ok: self.success = True except Exception: self.success = False def get_response(self): return self.response def get_text(self): return self.response.text def get_status_code(self): try: return self.response.status_code except AttributeError: return None