Я изменил скрипт, который извлекает данные с веб-страницы, но разница заключается в следующем:
он ищет все элементы <li id="nationalU">,
он приводит меня, но также сохраняет заголовок и, когда он отображается в комнате, читает строку за строкой. И он читает не только содержимое, которое находится внутри тегов <li id="nationalU">.
on *:TEXT:!nacional:#lps: nacional
alias nacional {
if ($hget(ns,stop)) {
.notice $nick Una sola vez por favor, espera por lo menos 10 segundos para enviar de vuelta.
| halt
}
.hadd -mu10 ns stop 1
.hadd -m ns nick $nick
.hadd -m ns chan $chan
.hadd -m ns port 443
.hadd -m ns domen multicuadros.000webhostapp.com
.hadd -m ns webpage https://multicuadros.000webhostapp.com/index.php
.hadd -m ns file $scriptdir $+ nacional.txt
; Eliminamos el archivo existente para asegurar que esté limpio
if ($exists($hget(ns,file))) .remove $hget(ns,file)
.sockclose nacional | if ($hget(ns,inc)) .hdel -sw ns inc
if (https: isin $hget(ns,webpage)) var %flag -e
.sockopen %flag nacional $hget(ns,domen) $hget(ns,port)
}
on *:SOCKOPEN:nacional:{
if ($sockerr) {
echo -s $hget(ns,domen) : Server is not available.
| halt
}
.sockwrite -nt $sockname GET $hget(ns,webpage) HTTP/1.0
.sockwrite -nt $sockname Host: $hget(ns,domen)
.sockwrite -nt $sockname User-Agent: *
.sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
.sockwrite -nt $sockname $str($crlf,2)
.sockwrite -nt $sockname
}
;===
on *:SOCKREAD:nacional:{
if ($sockerr > 0) {
echo -s $hget(ns,domen) : $error
| halt
}
:readmore
.sockread %temp_ns
if ($sockbr == 0) {
; Final de la lectura, comprobamos si hemos encontrado contenido
if (%temp_ns) {
; Filtramos el contenido para encontrar las etiquetas deseadas
var %ns_find = id="nacionalU"
if (%temp_ns && $regex(%temp_ns, /%ns_find/)) {
var %content = $strip($regml(%temp_ns,/<li id="nacionalU">(.*)<\/li>/s))
if (%content) {
.write -c $hget(ns,file) %content
}
}
}
return
}
; Si no hemos llegado al final, continuamos leyendo
; Ignoramos todas las líneas hasta que encontramos <li id="nacionalU">
if (!$hget(ns,html_started)) {
if ($regex(%temp_ns,/<li id="nacionalU">/i)) {
.hadd ns html_started 1
; Escribimos la línea actual en el archivo
.write -i $hget(ns,file) %temp_ns
}
goto readmore
}
; Si ya hemos encontrado <li id="nacionalU">, escribimos en el archivo
.write -i $hget(ns,file) %temp_ns
goto readmore
}
;===
on *:SOCKCLOSE:nacional:{
.echo -st $+(12,$hget(ns,domen),) - Lectura completada!
if ($exists($hget(ns,file)) && $lines($hget(ns,file)) > 0) {
msg $hget(ns,chan) 12Contenido de nacional:14 $read($hget(ns,file))
}
}
Сохраненный txt-файл выглядит следующим образом:
[flist=black]HTTP/1.1 200 OK
Date: Thu, 25 Apr 2024 14:17:52 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Server: awex
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Request-ID: 3485e3a9d7dab53b9782012d1f6b3be1
<ul><li id="nacionalU">
Intendente de Luque permanece en silencio y ausente tras muerte de mujeres arrastradas por raudal
</li><li id="nacionalU">
Video: Senad captura a supuesto traficante argentino en aparatoso procedimiento
</li><li id="nacionalU">
Fiscalía acusa y pide juicio oral para Joaquín Roa, ex ministro de la SEN
</li><li id="nacionalU">
Accidentado despegue de avión de la Fuerza Aérea en el Silvio Pettirossi
</li><li id="nacionalU">
Fiscal aún no tiene elementos penales contra municipio tras muerte de mujeres en Luque
[/flist]
