kylomas Posted January 5, 2017 Share Posted January 5, 2017 13 hours ago, kylomas said: Exactly why many insist that regexp should NOT be used as an HTML parser. I am not one of them. Just pointing out the possibilities. Regexp = Golf (fascinating and frustrating) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Champak Posted January 9, 2017 Author Share Posted January 9, 2017 On 1/5/2017 at 8:53 AM, mikell said: Waiting now for Champak's feedback Once again, I tip my hat and say bloody brilliant. I keep playing with it just to watch the speed . The sad thing is if it breaks down because of a website change, I know nothing about regex to repair it. I played with Regex a couple years ago for about two months and nearly went insane and just let it go, I've never simply let a function go before. I'm going to run more tests throughout the week and see how it works. For the most part it's only three states I'm in and around, so I should be good unless they change up the site. Right now I'm going to look into getting the actual values of the "Areas" select box, instead of what's visibly shown and then I'll have everything I need to complete all my functions of this page. Is that possible with the Read data from html Tables from raw HTML source or do I need to find a different way. Thanks. Link to comment Share on other sites More sharing options...
mikell Posted January 9, 2017 Share Posted January 9, 2017 53 minutes ago, Champak said: The sad thing is if it breaks down because of a website change Well, in this case any code will fail and will need to be repaired The used regex is not so complicated, the _ArrayDisplay reveals the trick - but I can explain it in details if you want 56 minutes ago, Champak said: I'm going to look into getting the actual values of the "Areas" select box This can be done using _IE funcs, but also using ... guess what ? Example below #include <Array.au3> $url1 = "http://www.newyorkgasprices.com/GasPriceSearch.aspx?typ=adv&fuel=A&srch=0&tme_limit=24" _GetAreas($url1) Func _GetAreas($url) $txt = StringRegExpReplace(BinaryToString(InetRead($url, 1)), '(?s).*<option value="All Areas"(.*?)</select>.*', "$1") ; Msgbox(0,"", $txt) $areas = StringRegExp($txt, '>(.+?)<', 3) _ArrayDisplay($areas) EndFunc Link to comment Share on other sites More sharing options...
Champak Posted January 9, 2017 Author Share Posted January 9, 2017 (edited) 1 hour ago, mikell said: This can be done using _IE funcs, but also using ... guess what ? Unfortunately I'm spoiled now , I'm going to try and stay away from _IE when it's possible lol. Cool, thanks. Not exactly what I needed, but more than enough for me to figure out what I needed. I changed it to the following: Func _GetAreas($url) $txt = StringRegExpReplace(BinaryToString(InetRead($url, 1)), '(?s).*<option value="All Areas"(.*?)</select>.*', "$1") ;ConsoleWrite($txt) $areas = StringRegExp($txt, '="(.+?)">', 3) Local $NewArray[UBound($areas)][2] For $i = 0 To UBound($areas) - 1 $Location = StringSplit($areas[$i], ",", 2) $NewArray[$i][0] = $Location[0] $NewArray[$i][1] = $Location[1] Next _ArrayDisplay($NewArray) From this example you provided, I have a VERY SLIGHT understanding of what's going on...more than the previous one . I'll probably play around with the site and regex just to see what's what and give it another go...at least with this simple example. If I have any general questions about RegEx I'll just inbox you...if that's cool. Thanks. Edited January 9, 2017 by Champak Link to comment Share on other sites More sharing options...
mikell Posted January 9, 2017 Share Posted January 9, 2017 1 hour ago, Champak said: I'm going to try and stay away from _IE when it's possible Hmm. I'm a regex addict - I confess - but not yet perverted enough to forget that _IE is generally much more reliable. but sooo slow though... Feel free to ask questions about regex, the way you want. It's cool. definitely. Link to comment Share on other sites More sharing options...
Gianni Posted January 9, 2017 Share Posted January 9, 2017 1 hour ago, mikell said: Hmm. I'm a regex addict - I confess - but not yet perverted enough to forget that _IE is generally much more reliable. but sooo slow though... Feel free to ask questions about regex, the way you want. It's cool. definitely. Excuse me, if you allow, I would like to make a small hijacking off topic. I would like to take advantage of the great skill with which you knows how to use regexp to ask a question. I know that you can get 1D array as a result of a regular expression, but there is some way to get multidimensional arrays as a result of any particular regular expression? Sorry if this question is probably trivial, but I know nearly nothing about regular expressions. (Also, I have seen surprising and unimaginable things done with regular expressions, so I tried to ask. ...who knows ..) Thanks Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted January 9, 2017 Share Posted January 9, 2017 51 minutes ago, Chimp said: there is some way to get multidimensional arrays as a result of any particular regular expression Alas, no. Too bad. The returns are always either strings or 1D arrays So it's the user's task to manage each case (as Champak did previously) or to build a little func to do the job Gianni 1 Link to comment Share on other sites More sharing options...
Gianni Posted January 9, 2017 Share Posted January 9, 2017 ok, thank you @mikell for your answer. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
alien4u Posted January 11, 2017 Share Posted January 11, 2017 @mikell You still deeply in love with Regexp nice to see you active... Link to comment Share on other sites More sharing options...
mikell Posted January 11, 2017 Share Posted January 11, 2017 Yes. Knowing about one percent of regex features and still learning Thanks 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