Sign in to follow this  
Followers 0
Vowles

Help Needed: Filtering text:

13 posts in this topic

Heres my problem/goal:

I have a webpage, It contains details, It is set out like this:

<tr>
    <td><b>Callsign:</b></td>
    <td align="right">Vowlesy</td>
</tr>

Now, I want to extract "Vowlesy" from this,and then apply the extracted text to a variable. ($Callsign?).

So I need the first set of <td>/</td> to see which $ to place the second set of <td>s vaule.

Iam quite well knowing in how AutoIT works but no where near can use it to its full yet.

All and any help on this will be greatly apprecitated.

Thanks

Vowles

Share this post


Link to post
Share on other sites



I hope thats help:

$get_source = _InetGetSource("Your webpage")
$Callsign = _StringBetween($get_source, 'td align="right">', '</td>')
MsgBox(0, "", "Callsign: " &$Callsign)

Func _StringBetween($s,$from,$to)
$x=StringInStr($s,$from)+StringLen($from)
$y=StringInStr(StringTrimLeft($s,$x),$to)
Return StringMid($s,$x,$y)
EndFunc

Share this post


Link to post
Share on other sites

maybe like this

Dim $result_3 = ""

$test = '<td align="right">Vowlesy</td>'

$L_loc = StringInStr($test, '">')

$result = StringTrimLeft( $test, $L_loc +1)

$R_loc = StringInStr($result, '</', 0, +1)

$result_2 = StringLeft( $result, $R_loc -1 )

If $result_2 <> $result_3 Then
    $result_3 = $result_2
;write the line to the file
    MsgBox(0,"test", "final result = " & $result_3)
EndIf
$Callsign =  $result_3

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Cheers guys! They gave me in insight into how to do it!

Also, Is there a way to have a line in a string of text?

$Test = "WE

weee"

??

Share this post


Link to post
Share on other sites

You mean:

$Test = "WE" &@CRLF &"weee"

?

Share this post


Link to post
Share on other sites

Cheers, Couldnt remeber the macro for it B)

Share this post


Link to post
Share on other sites

Use SciTe, im using it and its making my programming very simple!

Share this post


Link to post
Share on other sites

Here's another approach using StringRegExp() (available in the beta):

; You'd probably read this from a file or something
Local $Data = '<tr>' & @LF & '<td><b>Callsign:</b></td>' & @LF & '<td align="right">Vowlesy</td>' & @LF & '</tr>'
Local $RegExp = '<b>(.*?):</b>.*?<td align="right">(.+?)</td>'

Local $Tokens = StringRegExp($Data, $RegExp, 3)
; $Tokens[0] contains the first TD value minus the colon
; $Tokens[1] contains the second TD value

Assign($Tokens[0], $Tokens[1], 1)
MsgBox(0x40, '$Callsign', $Callsign)

Share this post


Link to post
Share on other sites

It really depends on how empty values should be handled.

My pattern will cause the match to fail for such a case (which could then be @Error-trapped to ignore that case), whereas your case (after some pending bug fixes to StringRegExp()) would return a blank value, which would cause the variable to be defined but empty... which is probably desired actually.

Share this post


Link to post
Share on other sites

this look more like html script than Autoit

Local $RegExp = '<b>(.*?):</b>.*?<td align="right">(.+?)</td>'

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

It almost is. B)

Local $RegExp = '<b>(.*?):</b>.*?<td align="right">(.+?)</td>'
Local $Tokens = StringRegExp($Data, $RegExp, 3)

The above code roughly translates to the following English:

I expect $data to contain a <b> tag, followed by some undefined number of characters, followed by a colon and a </b>, followed by any amount of characters, followed by <td align="right">, followed by one or more characters, followed by </td>. If $data does in fact fit that description then I want you to grab the bit between the <b> and the :</b> (i.e. the bit in the brackets) and the bit between the <td> tags (again in brackets) and return those two items as an array.

Regular expressions are a powerful tool (and I need to have them properly learnt before my exam tomorrow!), especially in this kind of case where you want to extract pieces of information from a longer string. It's great to have this functionality in AutoIt now and if one plans on doing any string manipulation like the above example, it's worthwhile to learn the basics.

Share this post


Link to post
Share on other sites

It almost is. B)

I need to have them properly learnt before my exam tomorrow!)

AutoIt now and if one plans on doing any string manipulation like the above example, it's worthwhile to learn the basics.

looks like you learnt it midy fine

learn a new language... ah

guess i will have too ... sooner or later

8)


NEWHeader1.png

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