diff --git a/html5lib/_inputstream.py b/html5lib/_inputstream.py
index a93b5a4e..6195abfd 100644
--- a/html5lib/_inputstream.py
+++ b/html5lib/_inputstream.py
@@ -1,7 +1,13 @@
from __future__ import absolute_import, division, unicode_literals
from six import text_type
-from six.moves import http_client, urllib
+
+try:
+ from six.moves import http_client, urllib
+except ModuleNotFoundError:
+ # Support for Python 3.12+ where six.moves is not available.
+ import http.client as http_client
+ import urllib
import codecs
import re
diff --git a/html5lib/filters/sanitizer.py b/html5lib/filters/sanitizer.py
index ea2c5dd3..5219c1c4 100644
--- a/html5lib/filters/sanitizer.py
+++ b/html5lib/filters/sanitizer.py
@@ -12,7 +12,11 @@
import warnings
from xml.sax.saxutils import escape, unescape
-from six.moves import urllib_parse as urlparse
+try:
+ from six.moves import urllib_parse as urlparse
+except ModuleNotFoundError:
+ # Support for Python 3.12+ where six.moves is not available.
+ import urllib.parse as urlparse
from . import base
from ..constants import namespaces, prefixes
diff --git a/html5lib/tests/test_stream.py b/html5lib/tests/test_stream.py
index efe9b472..063b4ca2 100644
--- a/html5lib/tests/test_stream.py
+++ b/html5lib/tests/test_stream.py
@@ -9,7 +9,13 @@
import pytest
import six
-from six.moves import http_client, urllib
+
+try:
+ from six.moves import http_client, urllib
+except ModuleNotFoundError:
+ # Support for Python 3.12+ where six.moves is not available.
+ import http.client as http_client
+ import urllib
from html5lib._inputstream import (BufferedStream, HTMLInputStream,
HTMLUnicodeInputStream, HTMLBinaryInputStream)