C Api

This is the technical documentation of the C api, compatible with ctypes. This API is an intermediate layer between the C++ library and Python. The python bindings use this API directly via ctypes.

Context

Context is a singleton object that mantains Qt5 application instance in memory and exposes some QtWebKit configuration options.

The current API is incomplete and in the near future it will expose lots of configuration options for the WebKit engine.

void* ph_context_init()
Return type:pointer to a Context instance.

This method returns a new Context instance. Context is a singleton, and if you repeatedly call this method, it always returns a pointer to the same object.

void ph_context_free()

Destroy a current instance of Context. If you call this method repeatedly, the behavior is unspecified.

void ph_context_clear_memory_cache()

Clears the memory used by webkit for the current thread.

void ph_context_set_object_cache_capacity(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)

Specifies the capabilities of the memory cache for dead objects such as stylesheets or scripts.

Parameters:
  • cacheMinDeadCapacity (int) – specifies the minimum number of bytes that dead objects should consume when the cache is under pressure.
  • cacheMaxDead (int) – is the maximum number of bytes that dead objects should consume when the cache is not under pressure.
  • totalCapacity (int) – specifies the maximum number of bytes that the cache should consume overall.
void ph_context_set_max_pages_in_cache(int num)

Sets the maximum number of pages to hold in the memory page cache to pages.

Parameters:
  • num (int) – number of pages to hold in the memory.
char* ph_context_get_all_cookies()

Returns a cookies array with all the available cookies in a current cookiejar singleton, encoded as JSON.

void ph_context_set_cookies(const char *cookies)

Add or overwrite cookies on the current cookiejar.

void ph_context_clear_cookies()

Clear all cookies available in a current cookiejar instance.

void ph_context_set_boolean_config(int key, int value)

Set WebKit configuration parameter.

void ph_context_set_int_config(int key, int value)

Set WebKit configuration parameter.

int32_t ph_context_get_boolean_config(int key)

Get WebKit configuration parameter value.

int32_t ph_context_get_int_config(int key)

Get WebKit configuration parameter value.

Web Page

This api exposes a web page and its frames functionality.

void* ph_page_create()

Create a new instance of a Page object and returns its pointer.

Return type:pointer to a Page object instance.
void ph_page_free(void *page)

Destroy a Page instance and frees the memory used by it.

Parameters:
void ph_page_set_viewpoint_size(void *page, int x, int y)

Set view point size to a page.

char *ph_page_get_cookies(void *page)

Get the cookies generated by the page.

void ph_page_set_initial_cookies(void *page, const char *cookies)

Set initial cookies to the page.

int32_t ph_page_load(void *page, char *url)

Load contents for a current page.

int32_t ph_page_is_loaded(void *page)

Checks if the Page is loaded.

char* ph_page_get_requested_urls(void *page)

Get a list of URLs requested in background when the page is loaded. The result is encoded as JSON.

char* ph_page_get_reply_by_url(void *page, const char *url)

Get downloaded data from one of the background requests.

void* ph_page_main_frame(void *page)

Get main frame from Page.

void ph_frame_free(void *frame)

Release a frame memory.

char* ph_frame_to_html(void *frame)

Get frame content as HTML.

char* ph_frame_evaluate_javascript(void *frame, char* js)

Evaluate JavaScript in a current frame and return its result as string.

void* ph_frame_capture_image(void *frame, const char *format, int quality)
void ph_image_free(void *image)
int64_t ph_image_get_size(void* image)
const char* ph_image_get_format(void* image)
void ph_image_get_bytes(void *image, void *buffer, int64_t size)
void* ph_frame_find_first(void *frame, const char *selector)
void* ph_frame_find_all(void *frame, const char *selector)
void* ph_webcollection_get_webelement(void *collection, int32_t index)
void* ph_webelement_find_all(void *element, const char *selector)
void* ph_webelement_take_from_document(void *element)
void* ph_webelement_previous(void *element)
void* ph_webelement_next(void *element)
void ph_webcollection_free(void *collection)
void ph_webelement_free(void *element)
char* ph_webelement_tag_name(void *element)
char* ph_webelement_inner_html(void *element)
char* ph_webelement_inner_text(void *element)
char* ph_webelement_get_classes(void *element)
char* ph_webelement_get_attnames(void *element)
char* ph_webelement_get_attr(void *element, const char *attrname)
int32_t ph_webcollection_size(void *collection)
int32_t ph_webelement_has_class(void *element, const char *classname)
int32_t ph_webelement_has_attr(void *element, const char *attrname)
int32_t ph_webelement_has_attrs(void *element)
int32_t ph_webelement_is_null(void *element)
void ph_webelement_remove_attr(void *element, const char *attrname)
void ph_webelement_add_class(void *element, const char *classname)
void ph_webelement_set_attr(void *element, const char *attrname, const char *value)
void ph_webelement_append_html(void *element, const char *htmldata)
void ph_webelement_append_element(void *element, void *elementement)
void ph_webelement_append_html_after(void *element, const char *htmldata)
void ph_webelement_append_element_after(void *element, void *elementement)
void ph_webelement_replace_with_html(void *element, const char *htmldata)
void ph_webelement_replace_with_element(void *element, void *elementement)
void ph_webelement_remove_all_child_elements(void *element)
void ph_webelement_remove_from_document(void *element)
void ph_webelement_wrap_with_html(void *element, const char *htmldata)
void ph_webelement_wrap_with_element(void *element, void *elementement)