This SDK provides the python libraries needed to make use of the Web Shrinker API services.
- Website Thumbnail / Screenshots API functions (v2)
- Website Category Lookup API functions (v2)
- Supports keep-alive to speed up multiple requests
- Throws meaningful exceptions to aid debugging
The best way to install is by using pip:
$ pip install webshrinkerThe SDK also depends on the "requests" package which should be installed by pip automatically.
Here is an example categorization request, just replace the <access key> and <secret key> placeholders with your actual account keys. You can find and create access keys via the Account Dashboard. Additional information can be found on the Website Categorization API v2 Reference.
importwebshrinkerws=webshrinker.Categories("<access key>", "<secret key>")
# this will list all the possible categories a website, URL, or IP address can be intry:
response=ws.list()
printresponseexceptwebshrinker.RequestExceptionase:
# an error happened while making the request (possible DNS or connection timeout issue)raiseexceptwebshrinker.ResponseExceptionase:
# a general error happened while receiving the responseraiseexceptwebshrinker.UnauthorizedExceptionase:
# the API access or secret key used is invalidraiseexceptwebshrinker.RequestLimitExceptionase:
# the account reached its request limitraise# this will lookup the categories for the URL: https://www.webshrinker.comtry:
response=ws.lookup("https://www.webshrinker.com")
printresponseifresponse["categorizing"] ==True:
print"** The URL is still being categorized, check back again soon **"exceptwebshrinker.RequestExceptionase:
# an error happened while making the request (possible DNS or connection timeout issue)raiseexceptwebshrinker.ResponseExceptionase:
# a general error happened while receiving the responseraiseexceptwebshrinker.UnauthorizedExceptionase:
# the API access or secret key used is invalidraiseexceptwebshrinker.RequestLimitExceptionase:
# the account reached its request limitraiseHere is an example categorization request, just replace the <access key> and <secret key> placeholders with your actual account keys. You can find and create access keys via the Account Dashboard. Additional information can be found on the Thumbnail API v2 Reference.
importwebshrinkerws=webshrinker.Thumbnails("<access key>", "<secret key>")
# this will fetch the thumbnail image for a URL as PNG binary datatry:
response=ws.image("https://www.webshrinker.com")
# the response variable contains the PNG image dataexceptwebshrinker.RequestExceptionase:
# an error happened while making the request (possible DNS or connection timeout issue)raiseexceptwebshrinker.ResponseExceptionase:
# a general error happened while receiving the responseraiseexceptwebshrinker.UnauthorizedExceptionase:
# the API access or secret key used is invalidraiseexceptwebshrinker.RequestLimitExceptionase:
# the account reached its request limitraise# this will return information about the thumbnail image for the URL: https://www.webshrinker.comtry:
response=ws.info("https://www.webshrinker.com")
printresponseexceptwebshrinker.RequestExceptionase:
# an error happened while making the request (possible DNS or connection timeout issue)raiseexceptwebshrinker.ResponseExceptionase:
# a general error happened while receiving the responseraiseexceptwebshrinker.UnauthorizedExceptionase:
# the API access or secret key used is invalidraiseexceptwebshrinker.RequestLimitExceptionase:
# the account reached its request limitraise- set_keep_alive(True|False): Enable/disable the use of session in the requests module which supports keep-alive (default: True)
- set_verify_ssl(True|False): Enable/disable the verification of the SSL endpoint (default: True)
- set_timeout(seconds): Sets the amount of time to wait for an API connection before raising an exception (default: 10 seconds)