How to Convert a Website URL Page to Text using Python

Cloudmersive
2 min readJul 28, 2022

--

An easy way to review the content on your (or any) website is to simply separate the text from the HTML code it is embedded within. There’s an easy way of doing that: just use our URL to TXT conversion API, and you can generate all plain text found on that URL page for subsequent insertion into whichever document or format you choose to edit within. Removing & analyzing your web copy is just that simple.

The below demonstration will help you to structure your API call using Python code examples. If you want, you can find additional code examples (including Java, Node.js, JavaScript & more) on the Cloudmersive API console page. Additionally, you can use this API as a connector in Microsoft Power Automate/Logic Apps. You’ll just need a Cloudmersive API key to authenticate, which you can get by registering a free account on our website.

Let’s start with Python SDK installation. Run the following command:

pip install cloudmersive-convert-api-client

Next, let’s include the imports:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint

After that, copy in the API key authorization snippet, and call the function:

# 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.ConvertWebApi(cloudmersive_convert_api_client.ApiClient(configuration))
input = cloudmersive_convert_api_client.UrlToTextRequest() # UrlToTextRequest | HTML to Text request parameters
try:
# Convert website URL page to text (txt)
api_response = api_instance.convert_web_url_to_txt(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertWebApi->convert_web_url_to_txt: %s\n" % e)

Now you’re all done; no more code required. Simple & easy.

--

--

Cloudmersive

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