MCPcopy
hub / github.com/unclecode/crawl4ai / sanitize_input_encode

Function sanitize_input_encode

crawl4ai/utils.py:142–150  ·  view source on GitHub ↗

Sanitize input to handle potential encoding issues.

(text: str)

Source from the content-addressed store, hash-verified

140 return sanitized_html
141
142def sanitize_input_encode(text: str) -> str:
143 """Sanitize input to handle potential encoding issues."""
144 try:
145 # Attempt to encode and decode as UTF-8 to handle potential encoding issues
146 return text.encode('utf-8', errors='ignore').decode('utf-8')
147 except UnicodeEncodeError as e:
148 print(f"Warning: Encoding issue detected. Some characters may be lost. Error: {e}")
149 # Fall back to ASCII if UTF-8 fails
150 return text.encode('ascii', errors='ignore').decode('ascii')
151
152def escape_json_string(s):
153 """

Callers 8

runMethod · 0.85
crawlMethod · 0.85
crawlMethod · 0.85
take_screenshotMethod · 0.85
arunMethod · 0.85
aprocess_htmlMethod · 0.85
runMethod · 0.85
process_htmlMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…