ro  fr  en  es  pt  ar  zh  hi  de  ru
ART 2.0 ART 3.0 ART 4.0 ART 5.0 ART 6.0 Pinterest

पाइथन और एचटीएमएल फाइलों का उपयोग करके साइटमैप एक्सएमएल कैसे उत्पन्न करें

On February 16, 2022, in Leadership Quantum-XX, by Neculai Fantanaru

आप यहां पूरा कोड देख सकते हैं:Https: // passatin.com / 6gn gp bv6

इंस्टॉलपायथन

आपको निम्न फ़ाइलों की आवश्यकता है, जिसे आप एक ही फ़ोल्डर में डाल सकते हैं:

- एक खाली फ़ाइल बनाएँ कहा जाता हैआर। एक्सएमएल(यह वह फ़ाइल है जिसमें सभी HTML पृष्ठ उत्पन्न किए जाएंगे)

- एक फ़ाइल बनाएँfinal_xml.txtजिसमें आपको इस टैग को पहली पंक्ति पर कॉपी करना होगा:

Urlset>

- एक फ़ाइल बनाएँSTART_XML.TXTजिसमें आपको शुरुआत में निम्नलिखित कोड होना होगा:

?एक्सएमएल संस्करण="1.0"एन्कोडिंग="Utf-8"?>
मेंUrlset
      Xmlns: एक्सएसआई="Http: // 呜呜। I 3.org/2001/xml स्कीमा-इंस्टेंस"
	  Xmlns: एक्सएचटीएमएल="Http: // 呜呜। I 3.org/1999/xhtml"
      एक्सएसआई: स्कीमालोकेशन="Http: // 呜呜 sitemaps.org / स्कीमा / साइटमैप / 0.9 http: // 呜呜 .sitemaps.org / स्कीमा / साइटमैप / 0.9 / साइटमैप। सीवर"
      Xmlns="Http: // 呜呜। Sitemaps.org / schemas / साइटमैप / 0.9">	  	  
- Www.चेक-डोमेन्स। com साइट मैप जनक ->

- एक फ़ाइल बनाएँmodel_xml.txtजहां आपको शुरुआत में निम्नलिखित कोड होना चाहिए:

  
    <स्थान>Https://your-website.com/example - डर .html
    2021-11-303 17: 19: 37 + 00: 00
    साप्ताहिक
    <प्राथमिकता>0.6400
  

पायथन कोड (इसे कहीं भी सहेजें, बस HTML फ़ाइलों के साथ अपने फ़ोल्डर के साथ पथ बदलें)

import os
import re
import random
import unidecode


def read_text_from_file(file_path):
    """
    Aceasta functie returneaza continutul unui fisier.
    file_path: calea catre fisierul din care vrei sa citesti
    """
    with open(file_path, encoding='utf8') as f:
        text = f.read()
        return text


def write_to_file(text, file_path):
    """
    Aceasta functie scrie un text intr-un fisier.
    text: textul pe care vrei sa il scrii
    file_path: calea catre fisierul in care vrei sa scrii
    """
    with open(file_path, 'wb') as f:
        f.write(text.encode('utf8', 'ignore'))

def creeaza_fisier_xml():
    lista_nume_fisiere = preia_nume_fisiere_html(
        'e:\\YOUR-FOLDER-WITH-HTML-FILES',
        # files to ignore
        ['404-1.html', '404-2.html', '404-3.html']
    )
    start_xml = read_text_from_file('start_xml.txt')
    final_xml = read_text_from_file('final_xml.txt')
    model_xml = read_text_from_file('model_xml.txt')

    xml_text = start_xml + '\n'
    link_pattern = re.compile('(.*?)')
    link = re.findall(link_pattern, model_xml)
    if len(link) != 0:
        link = link[0]

    for nume_fisier in lista_nume_fisiere:
        model = model_xml
        model = model.replace(link, 'https://YOUR-WEBSITE.com/' + nume_fisier)
        xml_text = xml_text + model + '\n'

    xml_text = xml_text + final_xml

    write_to_file(xml_text, 'rss.xml')
    print("Scriere efectuata cu succes.")

def preia_nume_fisiere_html(folder_fisiere_html, lista_fisiere_de_ignorat):
    lista_nume_fisiere_html = list()
    for f in os.listdir(folder_fisiere_html):
            if f.endswith('.html'):
                lista_nume_fisiere_html.append(f)
    lista_finala = list()
    for f in lista_nume_fisiere_html:
        if f not in lista_fisiere_de_ignorat:
            lista_finala.append(f)
    return lista_finala

def main():
    creeaza_fisier_xml()

if __name__ == '__main__':
    main()

That's all folks.

यदि आपको मेरा कोड पसंद है, तो कृपया इसे साझा करें

इस कोड को देखेंपावरशेलया पायथन कोडसंस्करण 3यासंस्करण 4यासंस्करण 5

 


Latest articles accessed by readers:

  1. An Eye To See And A Mind To Understand
  2. Turn Towards Me With An Eye Full Of Your Own Gaze
  3. The Snapshot Of Magic In God's Universe
  4. Rhythm Of My Heart

Donate via Paypal

Alternate Text

RECURRENT DONATION

Donate monthly to support
the NeculaiFantanaru.com project

SINGLE DONATION

Donate the desired amount to support
the NeculaiFantanaru.com project

Donate by Bank Transfer

Account Ron: RO34INGB0000999900448439

Open account at ING Bank

Join The Neculai Fantanaru Community



* Note: If you want to read all my articles in real time, please check the romanian version !

decoration
About | Site Map | Partners | Feedback | Terms & Conditions | Privacy | RSS Feeds
© Neculai Fântânaru - All rights reserved