drogon/core/scrapping_utils.py

36 lines
No EOL
1.2 KiB
Python

# -*- coding: utf-8 -*-
import requests
class UrlAttack():
headers = {'Upgrade-Insecure-Requests': "1",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
'Accept-Encoding': "gzip, deflate, br",
'Accept-Language': "en-US,en;q=0.9",
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/67.0.3396.99 Chrome/67.0.3396.99 Safari/537.36'}
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):
if self.success:
return self.response
def get_text(self):
if self.success:
return self.response.text