oct.core package

oct.core.exceptions module

exception oct.core.exceptions.FormNotFoundException

Bases: exceptions.Exception

Raised in case of FormNotFound with browser

exception oct.core.exceptions.LinkNotFound

Bases: exceptions.Exception

Raised in case of link not found in current html document

exception oct.core.exceptions.NoFormWaiting

Bases: exceptions.Exception

Raised in case of action required form if no form selected

exception oct.core.exceptions.NoUrlOpen

Bases: exceptions.Exception

Raised in case of no url open but requested inside browser class

exception oct.core.exceptions.OctGenericException

Bases: exceptions.Exception

Provide generic exception for reports

oct.core.generic module

oct.core.browser module

class oct.core.browser.Browser(session=None, base_url='')

Bases: object

This class represent a minimal browser. Build on top of lxml awesome library it let you write script for accessing or testing website with python scripts

Parameters:
  • session – The session object to use. If set to None will use requests.Session
  • base_url – The base url for the website, will append it for every link without a full url
add_header(name, value)

Allow you to add custom header, one by one. Specify existing name for update Headers will be used by every request

Parameters:
  • name (str) – the key of the header
  • value (str) – the associated value
Returns:

None

back()

Go to the previous url in the history property

Returns:the Response object
clean_session()

This function is called by the core of multi-mechanize. It cleans the session for avoiding cache or cookies errors, or giving false results based on cache

Returns:None
del_header(key)

Try to delete the ‘key’ of headers property

Parameters:key (mixed) – the key to delete
Returns:None

Will access the first link found with the selector

Raise:
oct.core.exceptions.LinkNotFound
Parameters:
  • selector – a string representing a css selector
  • url_regex – regex for finding the url, can represent the href attribute or the link content
Returns:

Response object

get_form(selector=None, nr=0, at_base=False)

Get the form selected by the selector and / or the nr param

Raise:
  • oct.core.exceptions.FormNotFoundException
  • oct.core.exceptions.NoUrlOpen
Parameters:
  • selector – A css-like selector for finding the form
  • nr – the index of the form, if selector is set to None, it will search on the hole page
  • at_base – must be set to true in case of form action is on the base_url page
Returns:

None

get_select_values()

Get the available values of all select and select multiple fields in form

Returns:a dict containing all values for each fields
history

Return the actual history

Returns:the _history property
Return type:list
static open_in_browser(response)

Provide a simple interface for lxml.html.open_in_browser function. Be careful, use this function only for debug purpose

Parameters:response
Returns:
open_url(url, data=None, back=False, **kwargs)

Open the given url

Parameters:
  • url – The url to access
  • data – Data to send. If data is set, the browser will make a POST request
  • back – tell if we actually accessing a page of the history
Returns:

The Response object from requests call

set_headers(headers)

Setter for headers property

Parameters:headers (dict) – a dict containing all headers
Returns:None
submit_form()

Submit the form filled with form_data property dict

Raise:
oct.core.exceptions.NoFormWaiting
Returns:Response object after the submit