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 Видаліть усі файли з менше 250 символів

On May 05, 2021, in Leadership Quantum-XX, by Neculai Fantanaru

Ви можете переглянути повний код тут:Https: // passatbin .com/eb me ef kr

ВстановитиПітонПотім, потім, потім

Варіант 1: Код нижче видаляє всі файли, які тривають менше 250 символів

import os
import re
import random
import unidecode
import nltk
from nltk import tokenize
# nltk.download('punkt')
import requests
from usp.tree import sitemap_tree_for_homepage

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()
        f.close()
        return text

FOLDER_LOCAL = 'd:\\Folder1'

counter_sterse = 0
for f in os.listdir(FOLDER_LOCAL):
    if f.endswith('.html') or f.endswith('.htm'):
        filepath = os.path.join(FOLDER_LOCAL, f)
        page_html = read_text_from_file(filepath)
        if len(page_html) < 250:
            os.remove(filepath)
            counter_sterse += 1
            continue

print("S-au sters {} fisiere".format(counter_sterse))

 

Варіант 2:The code below deletes all files that are less than 250 characters long in the section below:

<-почати->

words words words ...etc

<-остаточний->

Ви можете переглянути повний код тут:Https: // passatbin.com/au4xd6 тест

import os
import re
import random
import unidecode
import nltk
from nltk import tokenize
# nltk.download('punkt')
import requests
from usp.tree import sitemap_tree_for_homepage

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()
        f.close()
        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'))
        f.close()

# 1. Preluare site-uri de pe o anumita pagina (vezi variabila PAGE)
FOLDER_LOCAL = 'd:\\Folder1'

page_text_pattern = re.compile('<-- START -->([\s\S]*?)<-- FINAL -->')
counter_sterse = 0

for f in os.listdir(FOLDER_LOCAL):
    if f.endswith('.html') or f.endswith('.htm'):
        filepath = os.path.join(FOLDER_LOCAL, f)
        page_html = read_text_from_file(filepath)
        page_text = re.findall(page_text_pattern, page_html)
        if len(page_text) != 0:
            page_text = page_text[0]

            # print(page_text, len(page_text), filepath)

            if len(page_text) < 1500:
                os.remove(filepath)
                counter_sterse += 1
                continue

print("S-au sters {} fisiere".format(counter_sterse))

That's all folks.

Також дивіться цеВерсія 2або Версія 3абоВерсія 4абоВерсія 5абоВерсія 6абоВерсія 7


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