I'm currently working on an igloo aber and i've run into a problem with finding the item id. I can't grab the specific item id with a getstring function so i figured i'd try a regular expression even though i didn't fully understand them. I'll have an expression that roughly corresponds to this Code (Text): regexp.pattern = "process_igloo/.phtml_obj_id=(/d*) onclick/( /!/( 'Are you sure you wish to buy" & ShopList(i) i know this probably isn't the correct info in the means of what is actually in the source because i'm too lazy to open up my code and track it down . The only problem is when i try to test this on strHTML Code (Text): regexp.test(strHTML) it gives me an error saying the function test could not be performed on the obj regexp. I've also tried simplifying it to just getting Code (Text): regexp.pattern = "process_igloo/.phtml_obj_id=(/d*)" to see if there was a problem past getting the id but it continues to give me an error. Again i've simplified it even more to just using a login the would grab the welcom, username NP: np and it doesn't give me an error but when i try to test my regular expression it can't find it Code (Text): regexp.pattern = "Welcome, (.*) | NP: (/d*)" and the test will always return as a failed test even though i'm positive my login function works and if i try and execute it, it returns a null value. So can somebody please help explain to me what i'm doing wrong? i've googled it and all my findings just don't seem to help me figure out whats wrong. also here's my login function that grabs the welcome, username | NP: np Code (Text): Private Sub login(Username As String, Password As String) strHTML = Wrapper.GetWrapper("http://www.neopets.com/loginpage.phtml", "http://www.neopets.com/index.phtml") lblStatus.Caption = "Logging in (1/3)" strHTML = Wrapper.PostWrapper("http://www.neopets.com/hi.phtml", "destination=%2Findex.phtml&username=" & Username, "http://www.neopets.com/loginpage.phtml") lblStatus.Caption = "Logging in (2/3)" strHTML = Wrapper.PostWrapper("http://www.neopets.com/login.phtml", "destination=%2Findex.phtml&username=" & Username & "&password=" & Password, "http://www.neopets.com/hi.phtml") If InStrB(1, strHTML, "Location: /index.phtml") Then lblStatus.Caption = "Logged In" Set RegEx = New RegExp RegEx.Pattern = "Welcome, (.*) | NP: (/d)" If RegEx.Test(strHTML) = True Then Set colMatches = RegEx.Execute(strHTML) For Each Match In colMatches MsgBox (Match.Value) Next Else MsgBox ("could not match string") End If ElseIf InStrB(1, strHTML, "FROZEN") Then lblStatus.Caption = "Account Frozen" cmdLogin.Enabled = True ElseIf InStrB(1, strHTML, "Location: /badpassword.phtml") Then lblStatus.Caption = "Bad Password" cmdLogin.Enabled = True End If End Sub and i'd also be happy to pm trusted members the code i have for my igloo process although i'd have to clean it up so other people besides me can understand what's going on xD
Here's what I use in my iglooAber The getbetween function Code (Text): Public Function GetBetween(ByVal Source As String, ByVal Start As String, ByVal Finish As String) As String Dim Result = "" Dim A = InStr(1, Source, Start) + Len(Start) If A = 0 Then Result = "" Return Result Else Dim B = InStr(A, Source, Finish) If B = 0 Then Result = "" Return Result Else Result = Mid(Source, A, B - A) Return Result End If End If End Function And then, I check if there's a item in my list (lstList) can be found at the igloo and grab the ID to create the final "GET" to buy the item. FYI, "Response" is the return of the wrapper, so in this case, the igloo page. I remove all the text after the item and use the InStrRev to do the search. Code (Text): If Response.Contains(lstList.Items(i).ToString + " at") Then Response = Response.Remove(InStr(Response, lstList.Items(i).ToString) + lstList.Items(i).ToString.Length + 20, Response.Length - (InStr(Response, lstList.Items(i).ToString)) - lstList.Items(i).ToString.Length - 21) Response = Response.Remove(0, InStrRev(Response, "process_igloo")) Dim ItemLink As String = "http://www.neopets.com/winter/process_igloo.phtml?obj_info_id=" + Wrapper.GetBetween(Response, "obj_info_id=", "'") Response = Wrapper.Request("GET", ItemLink, "http://www.neopets.com/winter/igloo2.phtml") End If It's a bit messy but it work. There's some validation to do after if you bought an item but that's about it. Edit: Whitch wrapper are you using ??? The login seems fine.
Hmm, the escape character is "\" and not "/"... also digits are "\d" and not "/d" xD You inverted the two symbols... However, could you please post a snippet of the HTML you're trying to match? This way I can test it myself and check if the regex works.
oh wow i feel retarded xD i never would have caught that and that was the problem xD it all works now lol i can't believe i was so dumb and didnt realize it xD +rep ricky and tharoux thanks for the getstring function i'll have to try and convert it to vb6 some time so i can have a better getstring function oh and also one last thing no matter how many times i read things about how to use back references i can never understand. Is it possible to use a backreference outside of the regular expression? like for example this is the regular expression i have Code (Text): RegEx.Pattern = "process_igloo\.phtml\?obj_info_id=(\d*)' onClick=" & ChrW(34) & "if \( \!confirm\('Are you sure you wish to buy " & ShopList(i) & " at (\d*) NP\?'\)" to get to the item id i know you have to do something like ()\n or $1 but i could never figure it out...
to return things like that ceneret, you need to do this... Code (Text): RegEx.Pattern = "process_igloo\.phtml\?obj_info_id=(\d*)' onClick=" & ChrW(34) & "if \( \!confirm\('Are you sure you wish to buy " & ShopList(i) & " at (\d*) NP\?'\)" ObjID = RegEx.Replace(strHTML, "$1") Cost = RegEx.Replace(strHTML, "$2") Pretty sure that'll work...
ok thanks for the help sLaughter but when i do put my code as that i get something like this Spoiler the first line is the item name, the second line is supposed to be the ID, and the third is supposed to be the Cost, but for some reason when i try to get the backreference it gives me what looks to be server data sorry if i'm sounding stupid or needy but no matter how much i read about regular expressions and back references it just doesn't click for me xD EDIT: nevermind i figured it out, i have to access the backreference from the match itself not strHTML which actually makes a lot of sense since the match would have the back reference stored xD meaning it'd look something like this Code (Text): regex.replace(match, "$1")