From 19354df37cd7d29010cc340f5ee571b123ab5088 Mon Sep 17 00:00:00 2001 From: zhongxiao-chang <313725528+zhongxiao-chang@users.noreply.github.com> Date: Mon, 19 Oct 2026 19:21:31 +0800 Subject: [PATCH] fix(scraping): keep text after removed style/link/meta/noscript tags (#2416) `LXMLWebScrapingStrategy._scrap` removed continues after a style element.
", + "Styled text continues after a style element.", + id="style-inside-sentence", + ), + pytest.param( + "Plain text continues after a noscript element.
", + "Plain text continues after a noscript element.", + id="noscript-inside-sentence", + ), + pytest.param( + 'Text at the start of the paragraph.
', + "Text at the start of the paragraph.", + id="element-is-first-child", + ), + ], +) +def test_text_after_removed_element_is_kept(fragment, expected): + cleaned_html, markdown = scrape_and_markdown(fragment) + + assert expected in markdown + assert expected.replace("&", "&") in cleaned_html + # The element itself is still gone. + for tag in ("" + " after the style element." + ) + _, markdown = scrape_and_markdown(fragment) + + assert "Before **bold**" in markdown + assert "_after_ the style element." in markdown