Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Update to markdownify

Magnus Müllercf09b81af3e9
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index fbde50749..79c0b6739 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -1067,18 +1067,20 @@ You will be given a query and the markdown of a webpage that has been filtered t
page_html = html_serializer.serialize(enhanced_dom_tree)
original_html_length = len(page_html)
-
- # Use html2text for clean markdown conversion
- import html2text
-
- h = html2text.HTML2Text()
- h.ignore_links = not extract_links
- h.ignore_images = True
- h.ignore_emphasis = False
- h.body_width = 0 # Don't wrap lines
- h.unicode_snob = True
- h.skip_internal_links = True
- content = h.handle(page_html)
+ # save html to file
+ # with open('zzzpage_html.html', 'w') as f:
+ # f.write(page_html)
+
+ # Use markdownify for clean markdown conversion
+ from markdownify import markdownify as md
+
+ content = md(
+ page_html,
+ heading_style='ATX', # Use # style headings
+ strip=['script', 'style'], # Remove these tags
+ bullets='-', # Use - for unordered lists
+ code_language='', # Don't add language to code blocks
+ )
initial_markdown_length = len(content)
@@ -1089,6 +1091,9 @@ You will be given a query and the markdown of a webpage that has been filtered t
content, chars_filtered = self._preprocess_markdown_content(content)
final_filtered_length = len(content)
+ # save content to file
+ # with open('zzzcontent.md', 'w') as f:
+ # f.write(content)
# Content statistics
stats = {
diff --git a/pyproject.toml b/pyproject.toml
index be7ef1d95..449160e3f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -40,8 +40,8 @@ dependencies = [
"reportlab>=4.0.0",
"cdp-use>=1.4.0",
"pyotp>=2.9.0",
- "html2text>=2025.4.15",
"pillow>=11.2.1",
+ "markdownify>=1.2.0",
]
# google-api-core: only used for Google LLM APIs
# pyperclip: only used for examples that use copy/paste