From: Michael Shigorin <mike@osdn.org.ua>
To: community@altlinux.ru
Subject: [Comm] гм... (was: strage script needed)
Date: Sun, 24 Oct 2004 19:17:24 +0300
Message-ID: <20041024161724.GV2122@osdn.org.ua> (raw)
In-Reply-To: <opsf5vqpanhz2pp6@oc.peooc.net>
On Wed, Oct 20, 2004 at 01:09:51PM +0400, Aleksander N. Gorohovski wrote:
> >Имеется список в фомате хтмл, вида
> >ссылка тексттексттексттекст
> >ссылка тексттексттексттекст
> >ссылка тексттексттексттекст
> >ссылка тексттексттексттекст
> >ссылка тексттексттексттекст
> >необходима программа, которая обработает каждую запись списка
> >следующим образом: пройдя по ссылке найдёт на страничке определённый
> >текст по шаблону (наверное, регулярное выражение) и вставит этот текст
> >в конец строки.
> >Чем бы это сделать ?
> Думаю лучше чем Perl, ничто ни справится!
Ну почему. Ruby, например. :)
По мотивам
/usr/share/doc/ruby-doc-extra-0.1/ProgrammingRuby-0.3a/html/tut_io.html:
---
#!/usr/bin/ruby
require 'net/http'
while line = gets
pattern = Regex.new('http://[a-zA-Z0-9_.]+(:\d+)?(/\S+*)\s+(.*)$')
host, port, path, rest = line.scan(pattern)
next unless host
port = 80 unless port
path = "/" unless path
begin
conn = Net::HTTP.new(host, port)
resp, data = conn.get(path, nil)
if resp.message == "OK"
data.scan(/<img src="(.*?)"/) { |x| puts line + x }
end
rescue
next
end
end
---
Где-то так (не проверял :) -- должно работать фильтром, в данном
случае выводящим исходную строчку с добавлением пути к картинке
для каждой строчки stdin, соответствующей pattern, для которой
удалось вытащить страничку и найти в ней эти пути.
Но это так, просто пример похожий вспомнился -- писать вообще-то
всегда полезней самому, уж коль странного захотелось :-)
Просто такие вещи на shell пишутся (и особенно модифицируются) уж
больно болезненно, эффективнее получается сразу вложить время в
хороший язык.
--
---- WBR, Michael Shigorin <mike@altlinux.ru>
------ Linux.Kiev http://www.linux.kiev.ua/
next prev parent reply other threads:[~2004-10-24 16:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-20 10:04 [Comm] <JT> strage script needed Grigory Tuboltsev
2004-10-20 9:09 ` Aleksander N. Gorohovski
2004-10-24 16:17 ` Michael Shigorin [this message]
2004-10-20 10:06 ` Nick S. Grechukh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041024161724.GV2122@osdn.org.ua \
--to=mike@osdn.org.ua \
--cc=community@altlinux.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git