Sign in to follow this  
Followers 0
anyday

String Help

23 posts in this topic

#1 ·  Posted (edited)

im needing some advice on help with strings

im trying to pull some information out of a web page source

here is part of the source im looking at

Lets say my gui someone puts in the address off 6387 Tulane to search. well im trying to figure out the best way to grab the url associated with that address which in the source below would be

<a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073300&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">

and store that url in a var

<TABLE BORDER=0>

<tr bgcolor='#ccccff'>

<td></td>

<th width="300">OWNER NAME</th>

<th width="300">ADDRESS</th>

</tr>

<TR bgcolor=F0F0FF>

<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073300&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">Display</a></td>

<TD>ZOCCOLA WANDA L (LE)</td>

<TD> 6387 TULANE, HORN LAKE</td>

</TR><TR bgcolor=FFFFFF>

<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073400&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">Display</a></td>

<TD>JONES JAMES A ETUX</td>

<TD> 6405 TULANE, HORN LAKE</td>

</TR><TR bgcolor=F0F0FF>

<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073500&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">Display</a></td>

<TD>LEIGH ROBERT E III PROP LP</td>

<TD> 6411 TULANE, HORN LAKE0</td>

Edited by anyday

Share this post


Link to post
Share on other sites



HI,

and what is the question? :think:

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

im needing some advice on help with strings

im trying to pull some information out of a web page source

here is part of the source im looking at

does it matter what info is pulled? sorry, just kind of vague. check out the string functions in the helpfile, or the stringregexp() tutorial, or if you can give more details someone may be able to help you more directly

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

sorry hit submit post instead of preview :think: it should all be there now

Share this post


Link to post
Share on other sites

im needing some advice on help with strings

im trying to pull some information out of a web page source

here is part of the source im looking at

Lets say my gui someone puts in the address off 6387 Tulane to search. well im trying to figure out the best way to grab the url associated with that address which in the source below would be

<a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073300&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">

and store that url in a var

check out StringRegExp() there is a good tutorial in the tutorials section of the beta helpfile. you can make a pattern that finds the address, then ignores the tags, then grabs the next section, and have the whole thing done in one line.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

So if this address is found, what is the exact information you want to pull, and what is the desired output?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

if the address is found i want it just to pull the url that corresponds to that address out into a $var so that i can browse to that url

ive coded everything but the getting the url out of the body of the html

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

So if this address is found, what is the exact information you want to pull, and what is the desired output?

pay attention, smoke. he wants the link.

***edit***

i've got ten minutes before lunch and should probably practice my regexp anyway. i'll see if i can't whip that up real quick

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

pay attention, smoke. he wants the link.

***edit***

i've got ten minutes before lunch and should probably practice my regexp anyway. i'll see if i can't whip that up real quick

I was paying attention, I asked for what the "exact" output would look like. I already wrote a function to do this is why.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi,

maybe

#include <file.au3>
$search = '6387 Tulane'

Dim $aRecords
If Not _FileReadToArray("i.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
  ;Msgbox(0,'Record:' & $x, $aRecords[$x])
    If StringInStr($aRecords[$x], $search) <> 0 Then
        MsgBox(0,"",_StringBetween1($aRecords[$x-2], '<td><a href="', '>Display</a></td>'))
    EndIf
Next

Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0)
    $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start)
    Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start)
EndFunc ;==>_StringBetween1

i.txt

<TABLE BORDER=0>
<tr bgcolor='#ccccff'>
<td></td>
<th width="300">OWNER NAME</th>
<th width="300">ADDRESS</th>
</tr>
<TR bgcolor=F0F0FF>

<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073300&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">Display</a></td>
<TD>ZOCCOLA WANDA L (LE)</td>
<TD> 6387 TULANE, HORN LAKE</td>
</TR><TR bgcolor=FFFFFF>

<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073400&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">Display</a></td>
<TD>JONES JAMES A ETUX</td>
<TD> 6405 TULANE, HORN LAKE</td>

</TR><TR bgcolor=F0F0FF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073500&smurfid=0020f0f4f9f0f5f8f1f3f3f0f3f0f2f0f0f6f0f4f2f7f0f3f2f8f1f3f7f4f0f7">Display</a></td>
<TD>LEIGH ROBERT E III PROP LP</td>
<TD> 6411 TULANE, HORN LAKE0</td>

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

dont know if this matters but in IE the source displays's this way

The previous source was in firefox which did not include the &nbsp

Smoke if your asking what the url points to its just data on house's tax assessor data that i will sooner or later have displayed in the gui of my script but at this point i just need to get the url and navigate to it

<TABLE BORDER=0>
<tr bgcolor='#ccccff'>
<td></td>
<th width="300">OWNER NAME</th>
<th width="300">ADDRESS</th>
</tr>
<TR bgcolor=F0F0FF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073300&smurfid=0020f0f4f9f0f5f5f1f3f4f9f1f9f2f0f0f6f0f4f2f7f2f6f6f1f0f2f1f3f7f9">Display</a></td>
<TD>ZOCCOLA WANDA L (LE)</td>
<TD> 6387&nbsp;TULANE,&nbsp;&nbsp;HORN LAKE</td>
</TR><TR bgcolor=FFFFFF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073400&smurfid=0020f0f4f9f0f5f5f1f3f4f9f1f9f2f0f0f6f0f4f2f7f2f6f6f1f0f2f1f3f7f9">Display</a></td>
<TD>JONES JAMES A ETUX</td>
<TD> 6405&nbsp;TULANE,&nbsp;&nbsp;HORN LAKE</td>
</TR><TR bgcolor=F0F0FF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073500&smurfid=0020f0f4f9f0f5f5f1f3f4f9f1f9f2f0f0f6f0f4f2f7f2f6f6f1f0f2f1f3f7f9">Display</a></td>
<TD>LEIGH ROBERT E III PROP LP</td>
<TD> 6411&nbsp;TULANE,&nbsp;&nbsp;HORN LAKE0</td>
</TR><TR bgcolor=FFFFFF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073600&smurfid=0020f0f4f9f0f5f5f1f3f4f9f1f9f2f0f0f6f0f4f2f7f2f6f6f1f0f2f1f3f7f9">Display</a></td>
<TD>FRANKLIN ELVIRA L</td>
<TD> 6433&nbsp;TULANE,&nbsp;&nbsp;HORN LAKE0</td>
</TR><TR bgcolor=F0F0FF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200073700&smurfid=0020f0f4f9f0f5f5f1f3f4f9f1f9f2f0f0f6f0f4f2f7f2f6f6f1f0f2f1f3f7f9">Display</a></td>
<TD>JACKSON-COLEMAN IRREVOCABLE</td>
<TD> 6445&nbsp;TULANE,&nbsp;&nbsp;HORN LAKE</td>
</TR><TR bgcolor=FFFFFF>
<td><a href="APDSPREC.pgm?TASK=disp&Getparcel=108833010%20%20%20%20%20%200072400&smurfid=0020f0f4f9f0f5f5f1f3f4f9f1f9f2f0f0f6f0f4f2f7f2f6f6f1f0f2f1f3f7f9">Display</a></td>
<TD>PRUITT MARILYN ETVIR</td>
<TD> 6446&nbsp;TULANE,&nbsp;&nbsp;HORN LAKE0</td>
</TR><TR bgcolor=F0F0FF>
Edited by anyday

Share this post


Link to post
Share on other sites

I was paying attention, I asked for what the "exact" output would look like. I already wrote a function to do this is why.

fine then. no output, just stored url to variable. oh yeah, i won a few sit and go's last night. good stuff. gonna play live tourney tonight. off to lunch now...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

HI,

okay then you have to change the searchstring to $search = '6387&nbsp;TULANE'

Hope that helps.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Mega:

i tried your code out , seems to work i got a message box that pops up 5 times with url's

only thing is should just be 1 url for the match to address and store it in a var.

but thanks alot you gave me something to go off of

Edited by anyday

Share this post


Link to post
Share on other sites

Here's a stab at it:

$FileLocation = @DesktopDir & '\SomeFileName.txt'
$Address = "6387 TULANE"
$HrefArray = _StringRE_Between($FileLocation, '<a href="', '">Display')
$NameAddyArray = _StringRE_Between($FileLocation, '<TD>', '</td>')
For $x = 0 To UBound($NameAddyArray) - 1
    If StringInStr($NameAddyArray[$x], $Address) Then
        MsgBox(0, 'Test', 'Url = ' & $HrefArray[$x - 1] & @CR & _
        'Name = ' & $NameAddyArray[$x - 1] & @CR & _
        'Address = ' & $NameAddyArray[$x])
        ExitLoop
    EndIf
Next


Func _StringRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If Not @error Then Return $a_Array
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

smoke,

is there a var in there someone with the url as output?

i ran your code but didnt do anything visually. cant make out if there is a var that is the url :think:

i see there is a msgbox command in there but i never get a msgbox

Edited by anyday

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

smoke,

is there a var in there someone with the url as output?

i ran your code but didnt do anything visually. cant make out if there is a var that is the url :think:

i see there is a msgbox command in there but i never get a msgbox

All of the links are returned in a seperate array. $HrefArray... , because you have to find the address first, and the address is in another array, and it looked like it was always the 2nd option under name.

All I did was copy your example with name and address, and save that to a text file. And parse from there.

Edit:

And once the address is found, the Url is - 1 from the point that the address was found. If you did name, it would be the same value as $x.

Edit2:

Now that I think about that, my logic is flawed :(.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

i tried msgbox(0, "", $HrefArray[1]) no result.

an the link comes first then the name then the address

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

i tried msgbox(0, "", $HrefArray[1]) no result.

an the link comes first then the name then the address

Here, if URL for the Address is all you want:
$FileLocation = @DesktopDir & '\SomeFileName.txt'
$Address = "6405 TULANE"
$URL = _GetURL($FileLocation, $Address)
MsgBox(64, 'URL', $URL)

Func _GetURL($h_FileName, $s_Address)
    Local $aArray = _StringRE_Between($FileLocation, '<td>', '</td>')
    If IsArray($aArray) Then
        For $xCount = 0 To UBound($aArray) - 1
            If StringInStr($aArray[$xCount], $s_Address) Then
                $ReturnURL = StringRegExp($aArray[$xCount - 2], '(?i:<a href=")(.*?)(?i:</a>)', 3)
                If IsArray($ReturnURL) Then Return $ReturnURL[0]
                Return 0
            EndIf
        Next
    Else
        Return 0
    EndIf
    Return 0
EndFunc

Func _StringRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?i:' & $s_Start & ')(.*?)(?i:' & $s_End & ')', 3)
    If Not @error Then Return $a_Array
EndFunc
That worked for me with what you provided.

Edit:

And if you want to ever use the name, you can use 1 as the last parameter

$FileLocation = @DesktopDir & '\SomeFileName.txt'
$Address = "6405 TULANE"
$URL = _GetURL($FileLocation, $Address)
MsgBox(64, 'URL From Address', $URL)

$Name = "JONES JAMES A ETUX"
$URL = _GetURL($FileLocation, $Name, 1)
MsgBox(64, 'URL From Name', $URL)

Func _GetURL($h_FileName, $s_Address_Name, $i_Address_Name = 0)
    Local $aArray = _StringRE_Between($FileLocation, '<td>', '</td>')
    If IsArray($aArray) Then
        If $i_Address_Name = 0 Then
            For $xCount = 0 To UBound($aArray) - 1
                If StringInStr($aArray[$xCount], $s_Address_Name) Then
                    $ReturnURL = StringRegExp($aArray[$xCount - 2], '(?i:<a href=")(.*?)(?i:</a>)', 3)
                    If IsArray($ReturnURL) Then Return $ReturnURL[0]
                    SetError(1)
                    Return 0
                EndIf
            Next
        ElseIf $i_Address_Name = 1 Then
            For $xCount = 0 To UBound($aArray) - 1
                If StringInStr($aArray[$xCount], $s_Address_Name) Then
                    $ReturnURL = StringRegExp($aArray[$xCount - 1], '(?i:<a href=")(.*?)(?i:</a>)', 3)
                    If IsArray($ReturnURL) Then Return $ReturnURL[0]
                    SetError(1)
                    Return 0
                EndIf
            Next
        Else
            SetError(3)
            Return 0
        EndIf
    Else
        SetError(2)
        Return 0
    EndIf
    SetError(1)
    Return 0
EndFunc

Func _StringRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?i:' & $s_Start & ')(.*?)(?i:' & $s_End & ')', 3)
    If Not @error Then Return $a_Array
EndFunc
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

thanks smoke, i will try

also thanks mega, i tried your's and seems to be working

another ques:

lets say the url it comes up with is

http://www.desotoms.info/Webpgms/APDSPREC....7f2f2f5f4f8f2f4

is there an easy way to get some general info from that page like Landowner name: and such?

found one way using the _StringBetween1 from mega. thanks again.

in theat stringbetween1 function, is there a way to do _StringBetween1($text, 'Landowner Name:', @CR)

or whatever it is for the next line

Edited by anyday

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
Sign in to follow this  
Followers 0