codewars Surf

class codewars.surf.Surfer(loop=None)[source]

Library to surf the web in ASYNC style This class is designed to execute multiple request without pauzing / stopping the code.

get(url: str = None, header: dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}, auth: tuple = (), json: bool = False, decode: bool = False, timeout: int = 5)[source]

Execute a GET request

Parameters
  • url – Default: None Type: str Description: The request url

  • header – Default: Mozilla user agent Type: Dict Description: The headers of your request in key, value format

  • Auth – Default: () Type: Tuple Description: (Username : str, Password : str)

  • json – Default: False Type: Bool True: Returns json format False: Returns string format

  • decode – Default: False Type: Bool True: Decode json format to utf8 False: Skips this step

  • timeout – Default: 5 Type: int Description: Stops the request after timeout hit X seconds

Note

The parameter decode is useful for some websites / apis. Most of the time you do not need this option. But if a request still returns encoded data after a solid json request, then you might consider to turn this option on.

Returns

Type: Tuple Content: (Response Status Code : int, Response Data, ) Description: The response data depends on the settings provided.

Return type

Response

post(url: str = None, header: dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}, auth: tuple = (), data: dict = {}, json: bool = False, decode: bool = False, timeout: int = 5)[source]

Execute a POST request

Parameters
  • url – Default: None Type: str Description: The request url

  • header – Default: Mozilla user agent Type: Dict Description: The headers of your request in key, value format

  • Auth – Default: () Type: Tuple Description: (Username : str, Password : str)

  • data – Default: Empty dict Type: Dict Description: The date you would like to post

  • json – Default: False Type: Bool True: Returns json format False: Returns string format

  • decode – Default: False Type: Bool True: Decode json format to utf8 False: Skips this step

  • timeout – Default: 5 Type: int Description: Stops the request after timeout hit X seconds

Note

The parameter decode is useful for some websites / apis. Most of the time you do not need this option. But if a request still returns encoded data after a solid json request, then you might consider to turn this option on.

Returns

Type: Tuple Content: (Response Status Code : int, Response Data, ) Description: The response data depends on the settings provided.

Return type

Response