Vowles Posted October 29, 2005 Share Posted October 29, 2005 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 Link to comment Share on other sites More sharing options...
poisonkiller Posted October 29, 2005 Share Posted October 29, 2005 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 Link to comment Share on other sites More sharing options...
Valuater Posted October 29, 2005 Share Posted October 29, 2005 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) Link to comment Share on other sites More sharing options...
Vowles Posted October 29, 2005 Author Share Posted October 29, 2005 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" ?? Link to comment Share on other sites More sharing options...
poisonkiller Posted October 29, 2005 Share Posted October 29, 2005 You mean: $Test = "WE" &@CRLF &"weee" ? Link to comment Share on other sites More sharing options...
Vowles Posted October 29, 2005 Author Share Posted October 29, 2005 Cheers, Couldnt remeber the macro for it Link to comment Share on other sites More sharing options...
poisonkiller Posted October 29, 2005 Share Posted October 29, 2005 Use SciTe, im using it and its making my programming very simple! Link to comment Share on other sites More sharing options...
LxP Posted October 31, 2005 Share Posted October 31, 2005 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) Link to comment Share on other sites More sharing options...
w0uter Posted October 31, 2005 Share Posted October 31, 2005 shouldnt Local $RegExp = '<b>(.*?):</b>.*?<td align="right">(.+?)</td>' be Local $RegExp = '<b>(.*?):</b>.*?<td align="right">(.*?)</td>' My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
LxP Posted November 1, 2005 Share Posted November 1, 2005 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. Link to comment Share on other sites More sharing options...
Valuater Posted November 1, 2005 Share Posted November 1, 2005 this look more like html script than Autoit Local $RegExp = '<b>(.*?):</b>.*?<td align="right">(.+?)</td>' 8) Link to comment Share on other sites More sharing options...
LxP Posted November 1, 2005 Share Posted November 1, 2005 It almost is. 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. Link to comment Share on other sites More sharing options...
Valuater Posted November 1, 2005 Share Posted November 1, 2005 It almost is. 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 finelearn a new language... ahguess i will have too ... sooner or later8) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now