elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Ayuda con Bat o Vbs
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con Bat o Vbs  (Leído 8,519 veces)
AngelFire

Desconectado Desconectado

Mensajes: 118


WTF :)


Ver Perfil WWW
Re: Ayuda con Bat o Vbs
« Respuesta #10 en: 20 Febrero 2015, 19:26 pm »

casi completo de mucha ayuda me sirvio esto

Código:
salida.WriteLine (Mid(tmpStr,899,5)) &" "& (Mid(tmpStr,934+4,25))


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Ayuda con Bat o Vbs
« Respuesta #11 en: 20 Febrero 2015, 19:33 pm »

Modo de empleo
Código:
CScript.exe ".\Script.vbs" ".\Archivo1.txt" ".\Archivo2.txt" "etc..."


Source
Código
  1. ' Example: RegEx capture in textfile, By Elektro
  2.  
  3. Option Explicit
  4.  
  5. Dim args, arg, _
  6.    outPath, fullpath, fileName, fileExt, _
  7.    fso, file, fileContent, _
  8.    rgx, rgxMatches, rgxMatch, rgxValue
  9.  
  10. Set args = WScript.Arguments
  11. If args.Count = 0 Then
  12.   Wscript.Echo("Any filepath specified.")
  13.   Wscript.Quit(1)
  14. End If
  15.  
  16. outPath = ".\Output\"
  17. Set fso = WScript.CreateObject("Scripting.FileSystemObject")
  18. If Not fso.FolderExists(outPath) Then
  19.   Call fso.CreateFolder(outPath)
  20. End If
  21.  
  22. ' El primer grupo de esta expresión captura el string "cash out:" plus el valor decimal.
  23. ' El cuarto grupo de esta expresión captura el valor decimal.
  24. Set rgx = New RegExp
  25.    rgx.Pattern    = "Cash(\s+)?out(\:)?(\s+)?([\d\.]+)"
  26.    rgx.IgnoreCase = True
  27.    rgx.Global     = True
  28.  
  29. For Each arg in args
  30.  
  31.   fullPath    = fso.GetAbsolutePathName(arg)
  32.   fileName    = fso.GetBaseName(fullPath)
  33.   fileExt     = fso.GetExtensionName(fullPath)
  34.   fileContent = fso.OpenTextFile(fullPath, 1).ReadAll
  35.  
  36.   Set rgxMatches = rgx.Execute(fileContent)
  37.   Set file       = fso.CreateTextFile(outPath & "\" & fileName & "_new" & "." & fileext)
  38.  
  39.   Wscript.Echo("[+] Processing file: " & fullPath)
  40.   For Each rgxMatch in rgxMatches
  41.      rgxValue = rgxMatch.Submatches(3)
  42.      Wscript.Echo(rgxValue)
  43.      Call file.WriteLine("Cash Out: " & rgxValue)
  44.   Next
  45.  
  46.   file.Close
  47.  
  48. Next
  49.  
  50. Wscript.Quit(0)


Output

  • .\Archivo1.txt
Código:
asdadasdasdasd asdsadas asdasdasd cash out: 1.97 asdasdas asdasda
asdadasdasdasd asdsadas asdasdasd cash out: 212.34 asdasdas asdasda

  • .\Outpu\Archivo1_new.txt
Código:
Cash Out: 1.97
Cash Out: 212.34


Saludos


« Última modificación: 20 Febrero 2015, 19:44 pm por Eleкtro » En línea

AngelFire

Desconectado Desconectado

Mensajes: 118


WTF :)


Ver Perfil WWW
Re: Ayuda con Bat o Vbs
« Respuesta #12 en: 22 Febrero 2015, 18:05 pm »

Elektro excelente código ya que con el mio no conseguía tan buen resultado. Estoy intentando entenderlo aun ya que contiene un camión de cosas que nunca he usado porque te repito mi nivel es muy básico.
No se si notaste que use:
Código:
Fichero = "C:\Ejemplo\" & i &".txt"
Esto se debe que estamos probando solo con 3 archivos pero en la practica son aproximadamente 1 000 000 de txt.
Como te puedes dar cuenta esto es un problema a la hora de:
CScript.exe ".\Script.vbs" ".\Archivo1.txt" ".\Archivo2.txt" "etc..."



Creo que resuelvo con esto:
Código:
On Error Resume Next
For i = 1 To 100000
Set crack = CreateObject("WScript.Shell")
crack.Run "cscript.exe .\Script.vbs .\input\"&i&".txt",vbhide
wscript.sleep 500
next
MsgBox "Tarea Finalizada",0,"Prueba"

Cual seria la modificación a realizar en tu excelente código Elektro para poder sacar el valor de un Archivo1.txt que contenga:

Citar
<b>Cash Out: </b> 1.97x </p>
<b>Cash Out: </b> 212.34x </p>
Pensé que no seria un problema con el ejemplo que puse que Archivo1.txt era

Citar
asdadasdasdasd asdsadas asdasdasd cash out: 1.97 asdasdas asdasda
asdadasdasdasd asdsadas asdasdasd cash out: 212.34 asdasdas asdasda

para no complicar mucho las cosas.

Pero si es un problema a la hora de aplicarlo al Archivo1.txt en cuestion:

Citar
<b>Cash Out: </b> 1.97x </p>
<b>Cash Out: </b> 212.34x </p>



[MOD]: Está prohibido hacer doble post.
« Última modificación: 22 Febrero 2015, 20:28 pm por Eleкtro » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Ayuda con Bat o Vbs
« Respuesta #13 en: 22 Febrero 2015, 20:27 pm »

Citar
Cual seria la modificación a realizar en tu excelente código Elektro para poder sacar el valor de un Archivo1.txt que contenga:

Código:
<b>Cash Out: </b> 1.97x </p>
<b>Cash Out: </b> 212.34x </p>

Para sacar el "1.97" usa esta expresión:
Código
  1. rgx.Pattern = "(cash.+out.+\s+)([\d\.]+)"

Si quieres sacar el "1.97" incluyendo la "x" (que no se a que hace referencia), usa esta expresión:
Código
  1. rgx.Pattern = "(cash.+out.+\s+)([\d\.]+[^\s])"

Como he disminuido la cantidad de grupos de la expresión (para no hacer demasiado compleja la expresión regular por las etiquetas Html), debes usar esta modificación también:
Código
  1. rgxValue = rgxMatch.Submatches(1)

Saludos
« Última modificación: 22 Febrero 2015, 20:30 pm por Eleкtro » En línea

AngelFire

Desconectado Desconectado

Mensajes: 118


WTF :)


Ver Perfil WWW
Re: Ayuda con Bat o Vbs
« Respuesta #14 en: 22 Febrero 2015, 23:10 pm »

Moderador disculpe por el doble post pero cada vez que le daba eliminar en la cruz me decía que no se podía porque alguien lo estaba viendo, de todas maneras aceptada por mi parte la alerta de que no se acepta doble post.

Increíble funciona a la perfección para con x y sin x

Código:
<b>Cash Out: </b> 1.97x </p>
<b>Cash Out: </b> 212.34x </p>

Pero al pasarselo a 1.html no funciona :( alguna idea:
Código:
<!DOCTYPE html><html> <head> <title>Play Info -- xxxxxx.com</title> <link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon"> <link rel="icon" href="/img/favicon.ico" type="image/x-icon"> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height"/>  <link rel="stylesheet" href="/css/cb42743da.css" /> </head><body><div class="wrap"> <header> <nav class="nav-top-bar"> <div class="title"> <a href="/"> <img src="/img/logo.png" alt="logo" width="40px" /> <h1 class="hide-for-small-only">xxxxxx.com</h1> </a> </div>  <div class="show-for-small-up user-login">  <a href="/register">Register</a> <a href="/login">Log in</a>  </div> </nav> </header>  <div class="content">  <div class="row panel radius"> <h4>Game #<strong>1</strong> information</h4> <p> <b>Cash Out: </b> 2.46x </p> <p> <b>Played: </b>Sat Ene 12 2015 00:20:13 GMT+0000 (UTC) <small>7 months ago</small> </p> <hr> <h6>Players</h6> <table class="user-table"> <thead> <tr> <td>Player</td> <td>Bet</td> <td>Cash Out</td> <td>Bonus</td> <td>Profit</td> </tr> </thead> <tbody>  </tbody> </table> <h6><b>Hash:</b> <a href="/faq#fair">null</a></h6> </div> </div> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-54064423-1', 'auto');  ga('send', 'pageview'); </script></div></body></html>
« Última modificación: 23 Febrero 2015, 00:46 am por AngelFire » En línea

AngelFire

Desconectado Desconectado

Mensajes: 118


WTF :)


Ver Perfil WWW
Re: Ayuda con Bat o Vbs
« Respuesta #15 en: 23 Febrero 2015, 08:31 am »

Creo que esto ayuda full a entender la parte mas compleja de tu codigo al menos para mi ;D

http://www.tutorialspoint.com/vbscript/vbscript_reg_expressions.htm
https://www.addedbytes.com/blog/code/vbscript-regular-expressions/
« Última modificación: 23 Febrero 2015, 17:51 pm por AngelFire » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Ayuda con Bat o Vbs
« Respuesta #16 en: 24 Febrero 2015, 01:21 am »

funciona a la perfección para con x y sin x

Pero al pasarselo a 1.html no funciona :( alguna idea:
Código:
<!DOCTYPE html><html> <head> <title>Play Info -- xxxxxx.com</title> <link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon"> <link rel="icon" href="/img/favicon.ico" type="image/x-icon"> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height"/>  <link rel="stylesheet" href="/css/cb42743da.css" /> </head><body><div class="wrap"> <header> <nav class="nav-top-bar"> <div class="title"> <a href="/"> <img src="/img/logo.png" alt="logo" width="40px" /> <h1 class="hide-for-small-only">xxxxxx.com</h1> </a> </div>  <div class="show-for-small-up user-login">  <a href="/register">Register</a> <a href="/login">Log in</a>  </div> </nav> </header>  <div class="content">  <div class="row panel radius"> <h4>Game #<strong>1</strong> information</h4> <p> <b>Cash Out: </b> 2.46x </p> <p> <b>Played: </b>Sat Ene 12 2015 00:20:13 GMT+0000 (UTC) <small>7 months ago</small> </p> <hr> <h6>Players</h6> <table class="user-table"> <thead> <tr> <td>Player</td> <td>Bet</td> <td>Cash Out</td> <td>Bonus</td> <td>Profit</td> </tr> </thead> <tbody>  </tbody> </table> <h6><b>Hash:</b> <a href="/faq#fair">null</a></h6> </div> </div> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-54064423-1', 'auto');  ga('send', 'pageview'); </script></div></body></html>

El motor RegEx no fue diseñado para parsear documentos Html, RegEx no entiende la estructua Html, y para ciertas cosas se puede volver un auténtico desafio el diseñar la expresión correcta.

Código:
rgx.Pattern = "cash.+out.+\s+<\/\w+>\s+([\w\.]+)"
...
rgxValue = rgxMatch.Submatches(0)

Con esa expresión regular obtienes el valor "2.46x" en ese documento Html.

Para más info sobre el manejo de Regex, es preferible que leas la Wikipedia: http://en.wikipedia.org/wiki/Regular_expression

Saludos
En línea

AngelFire

Desconectado Desconectado

Mensajes: 118


WTF :)


Ver Perfil WWW
Re: Ayuda con Bat o Vbs
« Respuesta #17 en: 24 Febrero 2015, 02:10 am »

Excelente decididamente eres un duro en el tema funciona a la perfección. No pensé que creara tantos obstáculos desde el principio no dar el ejemplo del fichero en cuestión así como no hice mucho casos a que fuera txt o html pero ya veo cuan equivocado estaba.

Ok te voy diciendo como queda todo:
Asi descargo el 1000000 de resultados separados en carpetas de 100000.

Código
  1. On Error Resume Next
  2. For i = 1 To 100000
  3. Set crack = CreateObject("WScript.Shell")
  4. crack.Run "wget -r -nd -P 100000 -A .html -e robots=off --no-check-certificate https://www.xxxxx.com/game/"&i&".html",vbhide
  5. wscript.sleep 500
  6. next
  7. MsgBox "Tarea Finalizada",0,"Download"

Asi paso tu script de ayuda a los 100000 resultados

Código
  1. On Error Resume Next
  2. For i = 1 To 100000
  3. Set cmd = CreateObject("WScript.Shell")
  4. cmd.Run "cscript.exe .\Script.vbs .\game\100000\"&i&".html",vbhide
  5. wscript.sleep 500
  6. next
  7. MsgBox "Tarea Finalizada",0,"Valor"

Tu script

Código
  1. ' Example: RegEx capture in textfile, By Elektro
  2. 'CScript.exe ".\Script.vbs" ".\1.html" ".\2.html" "etc...
  3.  
  4. Option Explicit
  5.  
  6. Dim args, arg, _
  7.    outPath, fullpath, fileName, fileExt, _
  8.    fso, file, fileContent, _
  9.    rgx, rgxMatches, rgxMatch, rgxValue
  10. Set args = WScript.Arguments
  11. If args.Count = 0 Then
  12.   Wscript.Echo("Any filepath specified.")
  13.   Wscript.Quit(1)
  14. End If
  15.  
  16. outPath = ".\Output\100000\"
  17. Set fso = WScript.CreateObject("Scripting.FileSystemObject")
  18. If Not fso.FolderExists(outPath) Then
  19.   Call fso.CreateFolder(outPath)
  20. End If
  21.  
  22. ' El primer grupo de esta expresión captura el string "cash out:" plus el valor decimal.
  23. ' El cuarto grupo de esta expresión captura el valor decimal.
  24. Set rgx = New RegExp
  25.     rgx.Pattern = "Cash.+Out.+\s+<\/\w+>\s+([\w\.]+)"
  26.    rgx.IgnoreCase = True
  27.    rgx.Global     = True
  28.  
  29. For Each arg in args
  30.  
  31.   fullPath    = fso.GetAbsolutePathName(arg)
  32.   fileName    = fso.GetBaseName(fullPath)
  33.   fileExt     = fso.GetExtensionName(fullPath)
  34.   fileContent = fso.OpenTextFile(fullPath, 1).ReadAll
  35.  
  36.   Set rgxMatches = rgx.Execute(fileContent)
  37.   Set file       = fso.CreateTextFile(outPath & "\" & fileName & ".txt")
  38.  
  39.   Wscript.Echo("[+] Processing file: " & fullPath)
  40.   For Each rgxMatch in rgxMatches
  41.      rgxValue = rgxMatch.Submatches(0)
  42.      Wscript.Echo(rgxValue)
  43.      Call file.WriteLine("Cash Out: " & rgxValue)
  44.   Next
  45.  
  46.   file.Close
  47.  
  48. Next
  49.  
  50. Wscript.Quit(0)

Así uno todas las salidas de tu script en un solo fichero con 100000 lineas

Código
  1. On Error Resume Next
  2. For i = 1 To 100000
  3. Fichero = "C:\Play\output\100000\" & i &".txt"
  4. Set objFSO = CreateObject("Scripting.FileSystemObject")
  5. filepath = Fichero
  6. Set objInputFile = objFSO.OpenTextFile(filepath)
  7. tmpStr = objInputFile.ReadLine
  8. Set texto = CreateObject("Scripting.FileSystemObject")
  9. Set salida = texto.CreateTextFile (".\Salida100000.txt", True)
  10. salida.WriteLine (Mid(tmpStr,1,50)) & n
  11. Next
  12. MsgBox "Tarea Finalizada",0,"Play"

Y después puedo realizar el análisis importando Salida100000.txt  a excel pero realmente todo es para ver esto que pregunte aqui http://foro.elhacker.net/scripting/ayuda_con_excel-t430543.0.html, ya que puedo ver mas cosas pero la que mas me interesa aun no se jajajajajajaj.


Que tengo un script en python que lo hace pero me gustaría ver igual como se soluciona en excel ;).

Aquí la versión en español de lo que pasaste para los que no dominen mucho el ingles: http://es.wikipedia.org/wiki/Expresi%C3%B3n_regular
Gracias por todo.
« Última modificación: 25 Febrero 2015, 00:59 am por AngelFire » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Ayuda con Bat o Vbs
« Respuesta #18 en: 24 Febrero 2015, 03:27 am »

Excelente decididamente eres un duro en el tema funciona a la perfección. No pensé que creara tantos obstáculos desde el principio no dar el ejemplo del fichero en cuestión así como no hice mucho casos a que fuera txt o html pero ya veo cuan equivocado estaba.

No te preocupes, en un lenguaje limitado como VBS la única alternativa más o menos decente para parsear texto es utilizar RegEx, o eso, o a base de Splits + y comparaciones de String, lo que que se vuelve muy tedioso en este lenguaje.

Solo quería remarcarte que utilizar RegEx puede causarte frustración por problemas de diseño debido a sus limitaciones impuestas por naturaleza sobre estructuras Html, pero vaya, de poco importa ya que RegEx es lo único que puedes utilizar, a menos que cambies de lenguaje por uno más competente el cual disponga de herramientas eficientes para dicha tarea (dichas herramientas siempre pueden ser también el uso de librerías de terceros).

Saludos!
« Última modificación: 24 Febrero 2015, 03:30 am por Eleкtro » En línea

AngelFire

Desconectado Desconectado

Mensajes: 118


WTF :)


Ver Perfil WWW
Re: Ayuda con Bat o Vbs
« Respuesta #19 en: 24 Febrero 2015, 07:14 am »

El script presenta problemas para tipos:
Citar
16,002x
160,989.4x
1,900x
 :-\
En línea

Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines