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

Python र HTML फाईलहरूको प्रयोग गरी साइटमाप्स XML सिर्जना गर्ने

On February 16, 2022, in Python Scripts Examples, by Neculai Fantanaru

तपाईं यहाँ पूरा कोड हेर्न सक्नुहुन्छ:HTTPS: // पासेटिनबिबन

स्थापना गर्नुपाइथनत्यसोभए, त्यसोभए, त्यसपछि

तपाईंलाई निम्न फाईलहरू चाहिन्छ, जुन तपाईं समान फोल्डरमा राख्न सक्नुहुन्छ:

- खाली फाईल सिर्जना गर्नुहोस्RSS.XML(यो फाईल हो जसमा सबै HTML पृष्ठहरू उत्पन्न हुनेछ)

- एक फाईल सिर्जना गर्नुहोस्अन्तिम_xml.txtजसमा तपाईंले यो ट्याग पहिलो लाइनमा प्रतिलिपि गर्नुपर्दछ।

"मूसिसभविष्य बाणि

- एक फाईल सिर्जना गर्नुहोस्XML.TTXTजुनमा तपाईंसँग निम्न कोड हुनुपर्दछ:

<XML संस्करण="1.0"घेरिएको="UTF-8"?>
<<<<<<मूसिस
      XMLNs: XSI="Http: // Wooho। I.org/2001/xml स्क्रियन-उदाहरण" "
	  XMLNs: XHTML="Http: // Woohoo। Hever.org199999999999/xhml"
      Xsi: स्क्वामेन्ट="Http: // Woohoo .Sitemaps.org / Schamap / 0.9 HTTP: // WHTP
      XMLNs="Http: // Heohoo .siemapss.org / schahaas / chirmap / 0" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""भविष्य बाणि	  	  
---- www.Check-डोमेन :.com Peeemap बिजुली ----भविष्य बाणि

- एक फाईल सिर्जना गर्नुहोस्मोडेल_xml.txtजहाँ तपाईंसँग निम्न कोड सुरू गर्न आवश्यक पर्दछ:

  
    <स्पिन>Https://tour-2ebsite.com/example- अफ्रिका
    <चट्टान आमोड>2021-11-11--30T7: 19: zat + + +00: 00
    <परिवर्तनफ्रेक>साप्ताहिक
    <प्राथमिकता>0.64400
  

पाइथन कोड (यसलाई कहिँ पनि बचत गर्नुहोस्, केवल 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.

यदि तपाईंलाई मेरो कोड मनपर्यो भने, कृपया साझा गर्नुहोस्

यस कोड हेर्नुहोस्प्राथमिकवा पाइथन कोडहरूसंस्करण।अथवासंस्करण।अथवासंस्करण।

 


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