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

ວິທີການສ້າງໂປເຊດເຊີ Batch ດ້ວຍ PowerShell ແລະ regex ເພື່ອທົດແທນປ້າຍ HTML (ການແຍກ)

On Iunie 16, 2021, in Leadership and Attitude, by Neculai Fantanaru

ທ່ານສາມາດເບິ່ງລະຫັດເຕັມທີ່ນີ້:https: // passatin.com / x Gn qj qs7

ຕົວຢ່າງຫຼັກຂອງຫນ້າ HTML ທີ່ຈະຖືກດັດແປງດ້ວຍລະຫັດ PowerShell. ຄັດລອກຂໍ້ຄວາມຂ້າງເທິງໃສ່ເອກະສານ .html, ບັນທຶກໄວ້ໃນສະຖານທີ່c: \ folder1

   

 xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="ro">

ວິທີການສ້າງໂປເຊດເຊີຟ້ອນກັບ PowerShell ແລະ Regex ເພື່ອທົດແທນປ້າຍ HTML (Parsing)
 rel="canonical" href="https://MY-WEBSITE.COM" />
 name="description" content="I LOVE HTML and CSS"/>

 name="keywords" content="abordarea frontala a lucrurilor neelucidate"/>
 name="abstract" content="My laptop works just fine"/>
 name="Subject" content="I think I need a new car."/>
 property="og:url" content="https://otherwebsite.com"/>
 property="og:title" content="Nobody is here?" />
 property="og:description" content="Dance is my passion."/>





ລະຫັດ PowerShell ຂ້າງລຸ່ມນີ້ຈະສໍາເນົາເອົາເນື້ອໃນຂອງປ້າຍ HTML ໃສ່ແທັກອີກໂດຍການແຍກຂໍ້ມູນ. ທ່ານພຽງແຕ່ຕ້ອງການຕື່ມໃສ່ປ້າຍ<ຫົວຂໍ້>ແລະ

$sourcedir = "C:\Folder1\"
$resultsdir = "C:\Folder1\"

Get-ChildItem -Path $sourcedir -Filter *.html | ForEach-Object {
    $content = Get-Content -Path $_.FullName -Raw
	
# Copy the content of the tag 
	
    $replaceValue = (Select-String -InputObject $content -Pattern '(?<=).Matches.Value
    $content = $content -replace '(?<=,$replaceValue
    $content = $content -replace '(?<="@id": ").*(")',$replaceValue
	
# Copy the content of the tag   in the tags ABSTRACT, SUBJECT, OG:TITLE, HEADLINE, KEYWORDS            #</span>
	
    <span style="color: #996633">$replaceValue</span> = (<span style="color: #007020">Select-String</span> -InputObject <span style="color: #996633">$content</span> -Pattern <span style="background-color: #fff0f0">'(?<=<title>ວິທີການສ້າງໂປເຊດເຊີຟ້ອນກັບ PowerShell ແລະ Regex ເພື່ອທົດແທນປ້າຍ HTML (Parsing))').Matches.Value
    $content = $content -replace '(?<=,$replaceValue
    $content = $content -replace '(?<=,$replaceValue
    $content = $content -replace '(?<=,$replaceValue
    $content = $content -replace '(?<=,$replaceValue
    $content = $content -replace '(?<="headline": ").+(?=")',$replaceValue
    $content = $content -replace '(?<="keywords": "ວິທີການສ້າງໂປເຊດເຊີຟ້ອນກັບ PowerShell ແລະ Regex ເພື່ອທົດແທນປ້າຍ HTML (Parsing)",
	
# Copy the content of the tag $replaceValue = (Select-String -InputObject $content -Pattern '(?<=).Matches.Value
    $content = $content -replace '(?<=,$replaceValue
    $content = $content -replace '(?<="description": "ວິທີການສ້າງໂປເຊດເຊີຟ້ອນກັບ PowerShell ແລະ Regex ເພື່ອທົດແທນປ້າຍ HTML (Parsing) |  Neculai Fantanaru",
  
   Set-Content -Path $resultsdir\$($_.name) $content
}
  

ທາງເລືອກ. ນີ້ແມ່ນການສະແດງອອກ regex ເຊິ່ງຈະປ່ຽນແທັກ "ຄໍາທີ່" ໃນຫນ້າ HTML, ເພີ່ມເຄື່ອງຫມາຍຈຸດຫຼັງຈາກແຕ່ລະຄໍາ.

ໃຊ້ກັບ Notepad ++ -> CTR + F -> ກວດສອບ: ການສະແດງອອກປົກກະຕິ

SEARCH: (?s)<title>.*?<\/title>.*?<meta\x20name="keywords"\x20content="\K(\w+)|\G[^\w\r\n]+(\w+)  
REPLACE BY:  ?1\l\1:,\x20\l\2

That's all folks.

If you like my code, please SHARE IT

ທ່ານຍັງສາມາດເບິ່ງສະບັບລະຫັດເຂົ້າPython


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