back-end/threats_monitoring/downloader_ransomware.py
def download(self, url, user_agent, num_retries):
        """ This function downloads a website's source code.
            @parameters
                url             (str)       website's url
                user_agent      (str)       specifies the user_agent string
                num_retries     (int)       if a download fails due to a problem with the request (4xx) or the server
                                            (5xx) the function calls it self recursively #num_retries times
            @returns
                html_code   (str or None)   html code of web site or None if no code is returned
        """

        print("Downloading %s ... " % url)
        # set user-agent for this request
        headers = {'User-Agent': user_agent}
        try:
            resp = requests.get(url, headers=headers, proxies=self.proxy)
            # retrieve content
            html_code = resp.text
            # save the request's status code
            code = resp.status_code
            if resp.status_code >= 400:
                print('Download error:', resp.text)
                html_code = None
                if num_retries and 500 <= resp.status_code < 600:
                    # recursively retry 5xx HTTP errors
                    print("retry")
                    self.throttle.wait(url)
                    return self.download(url, user_agent, num_retries - 1)
        except RequestException as e:
            print('Download Exception error:', e)
            html_code = None
            code = e.errno

        return {'html_code': html_code, 'code': code}
 This function downloads a website's source code.
            @parameters
                url             (str)       website's url
                user_agent      (str)       specifies the user_agent string
                num_retries     (int)       if a download fails due to a problem with the request (4xx) or the server
                                            (5xx) the function calls it self recursively #num_retries times
            @returns
                html_code   (str or None)   html code of web site or None if no code is returned
        
This function downloads a website's source code.
@parameters
url             (str)       website's url
user_agent      (str)       specifies the user_agent string
num_retries     (int)       if a download fails due to a problem with the request (4xx) or the server
(5xx) the function calls it self recursively #num_retries times
@returns
html_code   (str or None)   html code of web site or None if no code is returned
This function downloads a website ' s source code . @parameters url ( str ) website ' s url user_agent ( str ) specifies the user_agent string num_retries ( int ) if a download fails due to a problem with the request ( 4xx ) or the server ( 5xx ) the function calls it self recursively #num_retries times @returns html_code ( str or None ) html code of web site or None if no code is returned
def download(self, url, user_agent, num_retries):
        print("Downloading %s ... " % url)
        headers = {'User-Agent': user_agent}
        try:
            resp = requests.get(url, headers=headers, proxies=self.proxy)
            html_code = resp.text
            code = resp.status_code
            if resp.status_code >= 400:
                print('Download error:', resp.text)
                html_code = None
                if num_retries and 500 <= resp.status_code < 600:
                    print("retry")
                    self.throttle.wait(url)
                    return self.download(url, user_agent, num_retries - 1)
        except RequestException as e:
            print('Download Exception error:', e)
            html_code = None
            code = e.errno
        return {'html_code': html_code, 'code': code}
def download ( self , url , user_agent , num_retries ) : print ( "Downloading %s ... " % url ) headers = { 'User-Agent' : user_agent } try : resp = requests . get ( url , headers = headers , proxies = self . proxy ) html_code = resp . text code = resp . status_code if resp . status_code >= 400 : print ( 'Download error:' , resp . text ) html_code = None if num_retries and 500 <= resp . status_code < 600 : print ( "retry" ) self . throttle . wait ( url ) return self . download ( url , user_agent , num_retries - 1 ) except RequestException as e : print ( 'Download Exception error:' , e ) html_code = None code = e . errno return { 'html_code' : html_code , 'code' : code }
This function downloads a website's source code.
This function downloads a website ' s source code .
""" This function downloads a website's source code.
            @parameters
                url             (str)       website's url
                user_agent      (str)       specifies the user_agent string
                num_retries     (int)       if a download fails due to a problem with the request (4xx) or the server
                                            (5xx) the function calls it self recursively #num_retries times
            @returns
                html_code   (str or None)   html code of web site or None if no code is returned
        """ # set user-agent for this request
 # retrieve content
 # save the request's status code
 # recursively retry 5xx HTTP errors

self
url
user_agent
num_retries