How to Convert a Website URL Page to Text using Python

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 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
# Convert website URL page to text (txt)
api_response = api_instance.convert_web_url_to_txt(input)
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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


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