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

    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
×