Jump to content
galan2015

String

Recommended Posts

galan2015

Good morning,

I'm making progress, slowly understand regular expressions. Today I started to have fun also with an array. All expressions of landing to a file. OK!

Now I have to add each line first element that will result a complete URL.

The hope in you.

Ps. Please give the command for now, trying to finally learn something;)

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <File.au3>

Local  $oe = StringRegExp('href="/account/5086.html">', '(?i)<A class=i href="(.*?)"',3)
For $i = 0 To UBound($oe) - 1
;MsgBox($MB_SYSTEMMODAL, "RegExp Test with- " & 1, $oe[$i])
Next
$oee =_ArrayDisplay($oe, "1D display")            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; <------------- trza zobaczyc f1 instrukcje helpu 
$sFilePath = @ScriptDir & "\test2.txt"

; Write array to a file by passing the file name.
_FileWriteFromArray($sFilePath, $oe[$i], 1)

; Display the file.
ShellExecute($sFilePath)

 

Share this post


Link to post
Share on other sites
galan2015

Test.txt:

<P class=row dataid="47" jQueryAbsolut320150502="120"><A class=i href="/get/13131231.html">
<P class=row dataid="48" jQueryAbsolut320150502="130"><A class=i href="/get/515151231.html">
<P class=row dataid="49" jQueryAbsolut320150502="132"><A class=i href="/get/123123.html">
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <File.au3>

Local  $oe = StringRegExp(FileRead(@ScriptDir&'/test.txt'), '(?i)<A class=i href="(.*?)"',3)
For $i = 0 To UBound($oe) - 1
;MsgBox($MB_SYSTEMMODAL, "RegExp Test with- " & 1, $oe[$i])
Next
$oee =_ArrayDisplay($oe, "1D display")            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; <------------- trza zobaczyc f1 instrukcje helpu 
$sFilePath = @ScriptDir & "\test2.txt"

; Write array to a file by passing the file name.
_FileWriteFromArray($sFilePath, $oe[$i], 1)

; Display the file.
ShellExecute($sFilePath)

They r wroten as /get/123123.html - i would add data before them to make whole url from _IEPropertyGet($oIE, "locationurl"))

Edited by galan2015

Share this post


Link to post
Share on other sites
nitekram

Not sure if this is what you are looking for or not, as I am not sure where you are getting the correct URL...can you show us a complete URL?

 

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <File.au3>

Local  $oe = StringRegExp(FileRead(@ScriptDir&'/test.txt'), '(?i)<A class=i href="(.*?)"',3)
_ArrayDisplay($oe, "1D display")

For $i = 0 To UBound($oe) - 1
;MsgBox($MB_SYSTEMMODAL, "RegExp Test with- " & 1, $oe[$i])
$oe[$i] = 'newURL.' & $i & '.html'
MsgBox($MB_SYSTEMMODAL, "RegExp Test with- " & 1, $oe[$i])
Next

$sFilePath = @ScriptDir & "\test2.txt"

; Write array to a file by passing the file name.
_FileWriteFromArray($sFilePath, $oe)

; Display the file.
ShellExecute($sFilePath)

 


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
iamtheky

 

$oe[$i] = 'newURL.' & $i & '.html'
 

 

If your guess is accurate, i think this should be

$oe[$i] = 'newURL.' & $oe[$i] & '.html'

 

 

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <File.au3>

Global $oe[3]

$oe[0] = stringregexp('<P class=row dataid="47" jQueryAbsolut320150502="120"><A class=i href="/get/13131231.html">' , '(?i)<A class=i href="(.*?)"' , 3)[0]
$oe[1] = stringregexp('<P class=row dataid="48" jQueryAbsolut320150502="130"><A class=i href="/get/515151231.html">' , '(?i)<A class=i href="(.*?)"' , 3)[0]
$oe[2] = stringregexp('<P class=row dataid="49" jQueryAbsolut320150502="132"><A class=i href="/get/123123.html">' , '(?i)<A class=i href="(.*?)"' , 3)[0]

For $i = 0 To UBound($oe) - 1
;MsgBox($MB_SYSTEMMODAL, "RegExp Test with- " & 1, $oe[$i])
$oe[$i] = 'newURL.com' & $oe[$i]
MsgBox($MB_SYSTEMMODAL, "RegExp Test with- " & 1, $oe[$i])
Next

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
nitekram

I was not sure, I was j

 

If your guess is accurate, i think this should be

$oe[$i] = 'newURL.' & $oe[$i] & '.html'

That could be, but was just showing where OP would enter the new info.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
galan2015

Guys u dont understand. I want every record that "stringRegExp" had the address that is currently displayed page at $ oie

This is page what im training my skillz

 

Func ZapiszHtmlPodglad() ; Przycisk Skanuj
local $url = _IEPropertyGet($oIE, "locationurl") ; <------- http://warsaw.craigslist.pl/search/eve

FileWrite( @ScriptDir& "\test.txt", _IEBodyReadHTML($oIE))
$adresyogloszen = StringRegExp(FileRead(@ScriptDir&'/test.txt'), '(?i)<A class=i href="(.*?)"',3)

For $i = 0 To UBound($adresyogloszen) - 1
$sFilePath = @ScriptDir & "\test2.txt"
FileWrite(@ScriptDir& '\test2.txt',$url&$adresyogloszen[$i])
_FileWriteFromArray($sFilePath, $adresyogloszen, 1)
Next
EndFunc

 

Edited by galan2015

Share this post


Link to post
Share on other sites
jguinch

?

#Include <Array.au3>

$url = "http://www.myurl.com"

$sHtml = '<P class=row dataid="47" jQueryAbsolut320150502="120"><A class=i href="http://example.com/url.php">' & @CRLF & _
         '<P class=row dataid="48" jQueryAbsolut320150502="130"><A class=i href="/get/515151231.html">' & @CRLF & _
         '<P class=row dataid="49" jQueryAbsolut320150502="132"><A class=i href="/get/123123.html">'

$sHtml = StringRegExpReplace($sHtml, '(?iU)<a class=i href="\K(?!http)', $url)
         
$aLinks = StringRegExp($sHtml, '(?iU)<a class=i href="(.+)"', 3)
_ArrayDisplay($aLinks)

 

  • Like 1

Share this post


Link to post
Share on other sites
galan2015

?

#Include <Array.au3>

$url = "http://www.myurl.com"

$sHtml = '<P class=row dataid="47" jQueryAbsolut320150502="120"><A class=i href="http://example.com/url.php">' & @CRLF & _
         '<P class=row dataid="48" jQueryAbsolut320150502="130"><A class=i href="/get/515151231.html">' & @CRLF & _
         '<P class=row dataid="49" jQueryAbsolut320150502="132"><A class=i href="/get/123123.html">'

$sHtml = StringRegExpReplace($sHtml, '(?iU)<a class=i href="\K(?!http)', $url)
         
$aLinks = StringRegExp($sHtml, '(?iU)<a class=i href="(.+)"', 3)
_ArrayDisplay($aLinks)

 

​Thank you, next question.

If the result of StringRegExp does not include search activity how can I skip the rest of tasks? I know i should use Something like that:
Func Lolo()
Local $file1= StringRegExp(FileRead($newsdata), '<DIV class=news>(.*?)</DIV></UL>',3)
If $file1 = 1 then ; He found it
For $i = 0 To UBound($file1) - 1
MsgBox(1,1,$file1[$i])
FileWrite($newsdata,$file1[$i]&@CRLF)
ElseIf $file1 = 0 then ; not found 
EndFunc ; just if Just If the program does find anything, I would like to end the function.
Endif
Endfuc
Just If the program does find anything, I would like to end the function.
 

 

Share this post


Link to post
Share on other sites
jguinch

$file1 cannot be equal to 1 because StringRegExp with option 3 ($STR_REGEXPARRAYGLOBALMATCH) returns either an array or 0 (and @error is set to 1 or 2).

You can test if $file1 is an array : If IsArray($file1) Then ..., or test if @error is set or no : If Not @error Then ...

 

Share this post


Link to post
Share on other sites
galan2015

$file1 cannot be equal to 1 because StringRegExp with option 3 ($STR_REGEXPARRAYGLOBALMATCH) returns either an array or 0 (and @error is set to 1 or 2).

You can test if $file1 is an array : If IsArray($file1) Then ..., or test if @error is set or no : If Not @error Then ...

 

​BUt i dont know how write it ;s

Share this post


Link to post
Share on other sites
jguinch

Func Lolo()
    Local $file1 = StringRegExp(FileRead($newsdata), '<DIV class=news>(.*?)</DIV></UL>',3)
    If @error Then Return ; Or If Not IsArray($file1)
    
    For $i = 0 To UBound($file1) - 1
        MsgBox(0, "", $file1[$i])
        FileWrite($newsdata,$file1[$i]&@CRLF) ; Are you sure you what to write in the same file ?
    Next
EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • ternal
      By ternal
      Hi,
      Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y).
      I did not put much efffort into error checking but so far I did not need it.
      For my applications so far it works perfectly however if someone is willing I want to test this extensivly.
      If anyone has big lists of random stuff to sort could you try this out please?
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
×