How to Convert a Website URL to Text in Python

Cloudmersive
2 min readJan 10, 2023

--

Any given URL page is made up of HTML-formatted text (and various multimedia) elements. When we want to access/review ONLY the text contents on a given URL page, we need to strip away the HTML formatting to return a plain text string.

With the free API solution provided below, you’ll be able to easily store plain text from any URL page using only the URL string in the process — and you can do it all with only a few lines of code. This API automatically copies HTML code from the URL provided and subsequently removes all HTML formatting elements, leaving only a plain text string behind.

To use this API for free, just copy and paste from the complementary Python code examples provided below and use a free-tier Cloudmersive API key to complete your API call (get one by registering a free account on our website).

Begin by running this command to install the Python SDK:

pip install cloudmersive-convert-api-client

Then include the remaining code snippet to add the imports/call the function:

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.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)

Once you include your free-tier API key, you’re good to go. You’ll have a limit of up to 800 API calls per month with no additional commitments (one your reach the free monthly limit, your total will simply reset the following month).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet