diff --git a/html/arabic/python/general/convert-html-to-markdown-python-extract-links-paragraphs/_index.md b/html/arabic/python/general/convert-html-to-markdown-python-extract-links-paragraphs/_index.md new file mode 100644 index 000000000..e05125fbd --- /dev/null +++ b/html/arabic/python/general/convert-html-to-markdown-python-extract-links-paragraphs/_index.md @@ -0,0 +1,181 @@ +--- +category: general +date: 2026-08-03 +description: تحويل HTML إلى Markdown باستخدام بايثون. تعلّم كيفية استخراج الروابط + من HTML واستخراج الفقرات من HTML في عملية تحويل واحدة وفعّالة. +draft: false +images: +- PLACEHOLDER_URL/og-image.png +keywords: +- convert html to markdown +- extract links from html +- extract paragraphs from html +language: ar +lastmod: 2026-08-03 +og_description: تحويل HTML إلى Markdown في بايثون مع مثال مختصر يوضح كيفية استخراج + الروابط من HTML واستخراج الفقرات من HTML مع حفظ النتيجة كملف Markdown. +og_image_alt: Screenshot of Python code converting an HTML file to Markdown with selected + links and paragraphs +og_title: تحويل HTML إلى Markdown في Python – دليل الاستخراج الكامل +schemas: +- author: GroupDocs + dateModified: '2026-08-03' + description: Convert HTML to Markdown using Python. Learn how to extract links from + HTML and extract paragraphs from HTML in a single, efficient conversion. + headline: Convert HTML to Markdown Python – extract links & paragraphs + type: TechArticle +- description: Convert HTML to Markdown using Python. Learn how to extract links from + HTML and extract paragraphs from HTML in a single, efficient conversion. + name: Convert HTML to Markdown Python – extract links & paragraphs + steps: + - name: Load the HTML document you want to convert + text: '```python from groupdocs.conversion import HTMLDocument, MarkdownSaveOptions, + Converter' + - name: Create a feature set that includes only the elements you need + text: '```python # Instantiate the feature collection. selected_features = MarkdownSaveOptions.Features()' + - name: Attach the feature set to the Markdown save options + text: '```python md_options = MarkdownSaveOptions() md_options.features = selected_features + ```' + - name: Perform the conversion and save the result as a Markdown file + text: '```python output_path = "YOUR_DIRECTORY/links_and_paragraphs.md" Converter.convert_html(html_doc, + md_options, output_path) print(f"Conversion complete. Markdown saved to {output_path}") + ```' + type: HowTo +tags: +- HTML conversion +- Markdown +- Python +title: تحويل HTML إلى Markdown باستخدام بايثون – استخراج الروابط والفقرات +url: /ar/python/general/convert-html-to-markdown-python-extract-links-paragraphs/ +--- + +{{< blocks/products/pf/main-wrap-class >}} +{{< blocks/products/pf/main-container >}} +{{< blocks/products/pf/tutorial-page-section >}} + +# تحويل HTML إلى Markdown باستخدام Python – استخراج الروابط والفقرات + +إذا كنت بحاجة إلى **تحويل HTML إلى Markdown**، فإن هذا الدرس يوضح لك طريقة عملية للقيام بذلك باستخدام Python مع استخراج **الروابط من HTML** و**الفقرات من HTML** بشكل انتقائي. ستشاهد مثالًا كاملاً قابلاً للتنفيذ يحفظ المحتوى المصفى كملف Markdown نظيف. + +يُعد تحويل HTML إلى Markdown خطوة شائعة عندما تريد وثائق خفيفة الوزن، محتوى موقع ثابت، أو مجرد تمثيل نصي بسيط لصفحة ويب. بنهاية هذا الدليل ستحصل على سكريبت يقوم بـ: + +1. تحميل مستند HTML من القرص. +2. تكوين مجموعة ميزات تحتفظ فقط بالروابط وعناصر الفقرات. +3. تنفيذ التحويل باستخدام GroupDocs Conversion SDK for Python. +4. كتابة النتيجة إلى ملف `.md`. + +## المتطلبات المسبقة + +قبل أن تبدأ، تأكد من وجود ما يلي: + +| المتطلب | لماذا يهم | +|-------------|----------------| +| Python 3.9+ | تستهدف الـ SDK إصدارات Python الحديثة. | +| حزمة `groupdocs-conversion` | توفر الفئات `HTMLDocument`، `MarkdownSaveOptions`، و`Converter` المستخدمة في المثال. | +| ملف HTML للاختبار (مثل `sample.html`) | المصدر الذي ستقوم بتحويله. | + +قم بتثبيت الـ SDK عبر pip: + +```bash +pip install groupdocs-conversion +``` + +> **نصيحة احترافية:** استخدم بيئة افتراضية (`python -m venv .venv`) لعزل الاعتمادات. + +## تحويل HTML إلى Markdown باستخدام Python + +تكمن جوهر عملية التحويل في بضع خطوات بسيطة. كل خطوة موضحة أدناه، والنص الكامل للسكريبت يظهر في نهاية المقال. + +### الخطوة 1: تحميل مستند HTML الذي تريد تحويله + +```python +from groupdocs.conversion import HTMLDocument, MarkdownSaveOptions, Converter + +# Replace YOUR_DIRECTORY with the path that contains your HTML file. +html_path = "YOUR_DIRECTORY/sample.html" +html_doc = HTMLDocument(html_path) +``` + +*لماذا هذه الخطوة؟* +`HTMLDocument` يقوم بتحليل الملف المصدر ويبني تمثيل DOM داخلي يمكن للمحول العمل معه. بدون تحميل المستند أولاً، لا تملك الـ SDK ما تعالجه. + +### الخطوة 2: إنشاء مجموعة ميزات تشمل فقط العناصر التي تحتاجها + +```python +# Instantiate the feature collection. +selected_features = MarkdownSaveOptions.Features() + +# Keep only hyperlinks. +selected_features.add(MarkdownSaveOptions.Features.LINK) + +# Keep only paragraph tags. +selected_features.add(MarkdownSaveOptions.Features.PARAGRAPH) +``` + +*لماذا نضيف هذه الميزات* +`MarkdownSaveOptions.Features` تعمل كمرشح. بإضافة `LINK` و`PARAGRAPH` نخبر المحول **باستخراج الروابط من HTML** و**باستخراج الفقرات من HTML**، متجاهلين الصور، الجداول، السكريبتات، وغيرها من العلامات التي قد لا تحتاجها في الـ Markdown النهائي. + +### الخطوة 3: إرفاق مجموعة الميزات بخيارات حفظ Markdown + +```python +md_options = MarkdownSaveOptions() +md_options.features = selected_features +``` + +*لماذا هذه الخطوة؟* +`MarkdownSaveOptions` تحتفظ بجميع تفضيلات التحويل. تعيين `selected_features` الذي تم إنشاؤه مسبقًا يضمن أن التحويل يطبق تكوين الفلتر الخاص بنا. + +### الخطوة 4: تنفيذ التحويل وحفظ النتيجة كملف Markdown + +```python +output_path = "YOUR_DIRECTORY/links_and_paragraphs.md" +Converter.convert_html(html_doc, md_options, output_path) +print(f"Conversion complete. Markdown saved to {output_path}") +``` + +*لماذا نستدعي `convert_html`* +`Converter.convert_html` هو نقطة الدخول في الـ SDK لتحويلات HTML‑to‑Markdown. يقرأ `HTMLDocument`، يطبق `md_options`، ويكتب الناتج المصفى إلى `output_path`. + +#### النتيجة المتوقعة + +سيحتوي الملف الناتج `links_and_paragraphs.md` فقط على تمثيلات Markdown للروابط ونص الفقرات، على سبيل المثال: + +```markdown +[Visit the homepage](https://example.com) + +This is the first paragraph of the article, describing the main topic. + +Another paragraph with more details. +``` + +جميع عناصر HTML الأخرى مثل ``، ``، أو `