How to Get the Language for an HTML Document in Python

Cloudmersive
2 min readJul 7, 2021

--

Knowing the language code of an HTML document can be helpful in optimizing the document for web searches. Instead of attempting to locate it within the HTML text, we are going to demonstrate how you can automatically retrieve the language code by using an API in Python.

We will begin by running this command to install the SDK:

pip install cloudmersive-convert-api-client

Next, we can input the target file or file URL into the following code:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.EditHtmlApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Optional: Input file to perform the operation on. (optional)
input_file_url = 'input_file_url_example' # str | Optional: URL of a file to operate on as input. (optional)
try:
# Gets the language for the HTML document
api_response = api_instance.edit_html_html_get_language(input_file=input_file, input_file_url=input_file_url)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditHtmlApi->edit_html_html_get_language: %s\n" % e)

This will return the two-letter language code in no time at all. To retrieve your API key, visit the Cloudmersive website to register for a free account; this will provide 800 monthly calls across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet