![]() |
Olá e boas-vindas de Estados Unidos para o UNIX e Linux Forum! Obrigado por visitar e fazer parte da nossa comunidade global.
|
|
google unix.com
|
|||||||
| Fóruns | Registar | Fórum Regimento | Ligações | Álbuns | FAQ | Lista deputados | Calendário | Pesquisa | Today's Posts | Mark Forums Read |
| Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui. |
Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
|
||||
| Fio | Thread Starter | Fórum | Respostas | Última postagem |
| nome do arquivo de transformação | VRMS | Programação Shell Script e | 16 | 05-27-2008 09:49 |
| Cor Transformação Língua 1.4.1 (Default sucursal) | iBot | Software Release - RSS Notícias | 0 | 03-18-2008 08:10 |
| Evento Transformation Services | iBot | Complex Event Processing RSS Notícias | 0 | 08-24-2007 04:30 |
| Aplicar transformação lógica em 2 arquivos diferentes | HAA | Programação Shell Script e | 1 | 07-10-2007 05:33 |
| Transformação maiúscula | Dark Angel | UNIX para Dummies Perguntas & Respostas | 1 | 01-24-2002 04:17 |
![]() |
|
|
Linkback | Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Oi lá,
Estou tentando extrair automaticamente horários a partir de um site. A página está exibindo os horários http://www.natureetdecouvertes.com/p...sp?mag_cod\u003dxxx com xxx indo 101-174 Eu consegui obter o seguinte resultado: Código:
le lundi de 10.30 19.30
le mardi de 9.30 19.30
blank
le jeudi de 9.30 19.30
le vendredi de 9.30 19.30
le samedi de 10.30 21.30
blank
em branco é uma linha em branco reais (não exibindo nada) Como posso agora obter o resultado final: Código:
"10:30 19:30|09:30 19:30| |09:30 19:30|09:30 19:30|10:30 21:30| " Santiago |
|
||||
|
Código:
awk -F'[^0-9]+' '{b=b (NR>1?"|":"")($2?sprintf("%02d:%02d %02d:%02d",$2,$3,$4,$5):"")}END{print b}' yourfile.txt
Código:
awk -F'[^0-9]+' '{b=b (NR>1?"|":"")($2?sprintf("%02d:%02d %02d:%02d",$2,$3,$4,$5):sprintf("%11s",""))}END{print b}' yourfile.txt
Última edição por colemar; em 05/26/2009 06:32.. |
|
||||
|
se você tiver o Python, uma quase total solução alternativa
Código:
#!/usr/bin/env python
import urllib2,re
pat=re.compile(""".*<span class="tdBlancBold">(.*)<div align="center">.*""",re.M|re.DOTALL)
days=['lundi','mardi','mercredi','jeudi','vendredi','samedi','dimanche']
url="http://www.natureetdecouvertes.com/pages/gener/view_FO_STORE_corgen.asp?mag_cod=%s"
for num in range(101,174):
page=urllib2.urlopen(url % str(num))
data=page.read()
if not "Impossible" in data:
result = pat.findall(data)
store={}
for i in result:
for j in i.split("<br>"):
j=j.strip()
if j.startswith("le"):
j=j.split()
if j[1] in days:
t1,t2=j[-3],j[-1]
store.setdefault(j[1],[])
store[j[1]].extend([t1,t2])
for DAY in days:
try:
print "%s |" %( ' '.join(store[DAY])),
except:
print "\t\t|",
print ""
else:
print "Page not found ",url % str(num)
Código:
# python test.py 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 19.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | | 10.00 21.00 | 10.00 20.00 | | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | | 10.00 21.00 | 10.00 21.00 | 10.00 21.00 | 10.00 21.00 | 10.00 21.00 | 10.00 20.00 | | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | | 10.00 20.00 | 10.00 21.00 | 10.00 21.00 | 10.00 21.00 | 10.00 21.00 | 10.00 20.00 | | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | | Page not found http://www.natureetdecouvertes.com/pages/gener/view_FO_STORE_corgen.asp?mag_cod=110 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | 10.00 19.30 | | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | 10.00 20.00 | | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | 9.30 19.30 | | |
![]() |
| Marcadores |
| Tags |
| awk, sed |
| Thread Tools | Pesquisar este Thread |
| Display Modes | Esta taxa Thread |
|
|