|
-
Apr 18th, 2008, 12:07 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Need help replacing a url!!
Hey i am making a program that get all the links of the page but now i have a problem, with the links i got i only need a id example: URL: websiteurl.com/userID=1000 <-- than i only need the part 1000
and all the url's begin with websiteurl.com/userID=*****
but the ID's variate from 1000 to 100000 the script i use:
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim s As String
For i = 0 To browser.Document.links.length - 1
If InStr(1, browser.Document.links.Item(i).href, "websiteurl.com/userID=") = 1 Then
s = browser.Document.links.Item(i).href
script.AddItem s
End If
Next i
End Sub
Private Sub Form_Load()
Dim i As String
browser.Navigate Text1.Text
End Sub
Private Sub script_DblClick()
browser.Navigate script
End Sub
-
Apr 18th, 2008, 12:08 PM
#2
Re: Need help replacing a url!!
-
Apr 18th, 2008, 12:31 PM
#3
Re: Need help replacing a url!!
See if this is what you want
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim s As String
For i = 0 To browser.Document.links.length - 1
If InStr(1, browser.Document.links.Item(i).href, "websiteurl.com/userID=") = 1 Then
s = browser.Document.links.Item(i).href
script.AddItem s & CStr(1000 + i) '<-------- IS THIS WHAT YOU MEAN
End If
Next i
End Sub
Private Sub Form_Load()
Dim i As String
browser.Navigate Text1.Text
End Sub
Private Sub script_DblClick()
browser.Navigate script
End Sub
-
Apr 18th, 2008, 12:47 PM
#4
Thread Starter
Addicted Member
Re: Need help replacing a url!!
No i want the ID thats in the url example:
thesite.com/userID=123123
thesite.com/userID=123326
thesite.com/userID=294929
thesite.com/userID=2949
Than i want a list with:
123123
123326
294929
2949
-
Apr 18th, 2008, 01:16 PM
#5
Re: Need help replacing a url!!
Then just do a reverse InStr to find the first occurance of a = sign and extract out the ids which will be at the postion of the = sign +1 to the end of the link (I'm assuming that the id number is the very end of the link and nothing else follows it).
Link = thesite.com/userID=123123 <----123123 is the very last text in the link
So,
q = InStrRev(Link, "=")
If q > 0 Then s = mid(Link, q+1)
-
Apr 18th, 2008, 02:41 PM
#6
Lively Member
Re: Need help replacing a url!!
Last edited by goldenix; Apr 18th, 2008 at 03:20 PM.

M.V.B. 2008 Express Edition
-
Apr 18th, 2008, 02:57 PM
#7
Re: Need help replacing a url!!
The ids will not always be 4 characters
In his opening post he said
...the ID's variate from 1000 to 100000
-
Apr 18th, 2008, 03:05 PM
#8
Re: Need help replacing a url!!
Easiest way
Code:
MsgBox Split(myURLString, "=")(1)
Pradeep
-
Apr 18th, 2008, 03:19 PM
#9
Lively Member
Re: Need help replacing a url!!
ok ok hire is universal code: we can assume that url may contain multuiple =, so:
http://www.homeandlearn.co.uk/net/nets7p6.html
Code:
Dim URL = "www.thesite.com/userID=123123"
For i = 1 To URL.Length
MsgBox(URL.Substring(URL.Length - i, i)) ' this is hire to show you what i mean by cuttin goff
'start cutting off 1 char from the end if the URL until we get this: =123123 (>= 0 means if found "=")
If URL.Substring(URL.Length - i, i).IndexOf("=") >= 0 Then
'now we have =123123 & we replace = with nothing & vuala
MsgBox(URL.Substring(URL.Length - i, i).Replace("=", ""))
Exit For
End If
Next
Last edited by goldenix; Apr 18th, 2008 at 03:23 PM.

M.V.B. 2008 Express Edition
-
Apr 18th, 2008, 03:23 PM
#10
Re: Need help replacing a url!!
That is definitely the most unneccessary way to do it but if it pleases you then go for it.
-
Apr 18th, 2008, 03:27 PM
#11
Lively Member
Re: Need help replacing a url!!
 Originally Posted by jmsrickland
That is definitely the most unneccessary way to do it but if it pleases you then go for it.
You know better way? please feel free to share your idea. I suggested that code, cuz of my limited knowledge..(just started using this language you know & to find a decent vb. guide is really hard, the help file is totally useless you know. )
Edit: ok i think you can do it also by splitting the URL by "=" & the search Splits for userID= & if found replace userID= with nothing, but i dont think the code will be much shorther.
Last edited by goldenix; Apr 18th, 2008 at 03:32 PM.

M.V.B. 2008 Express Edition
-
Apr 18th, 2008, 03:47 PM
#12
Re: Need help replacing a url!!
I already showed you in post #5
-
Apr 18th, 2008, 03:49 PM
#13
Re: Need help replacing a url!!
 Originally Posted by jmsrickland
Then just do a reverse InStr to find the first occurance of a = sign and extract out the ids which will be at the postion of the = sign +1 to the end of the link (I'm assuming that the id number is the very end of the link and nothing else follows it).
Link = thesite.com/userID=123123 <----123123 is the very last text in the link
So,
q = InStrRev(Link, "=")
If q > 0 Then s = mid(Link, q+1)
+1
Why make it more complicated than it needs to be...if there were other parameters in the URL then maybe it would need some modifications but for the OP's question I don't see any need for complicating it or even using the split function.
Just my opinion though.
-
Apr 19th, 2008, 01:45 PM
#14
Thread Starter
Addicted Member
Re: Need help replacing a url!!
I still didn't find a solution
I only get wrong answers
I Need a ID grabber that grabs all the id's from a website and the url is always
thesite.com/userid=conf=123333 ( there are 2 times a "=" sing ) and with the solutions i got i didn't find a solution only cutting of a already existing url but the id is always different!
so it isn't always thesite.com/userid=conf=123333 it also can be
thesite.com/userid=conf=999999
thesite.com/userid=conf=99999
thesite.com/userid=conf=9999
thesite.com/userid=conf=72481
thesite.com/userid=conf=36789
thesite.com/userid=conf=1596
thesite.com/userid=conf=12374
thesite.com/userid=conf=756916
thesite.com/userid=conf=89456
thesite.com/userid=conf=33274
thesite.com/userid=conf=123333
thesite.com/userid=conf=9561
thesite.com/userid=conf=32749
thesite.com/userid=conf=216872
thesite.com/userid=conf=984651
AND tons of more id's
-
Apr 19th, 2008, 02:15 PM
#15
Re: Need help replacing a url!!
What is about what I showed you that doesn't work?
You tell us that in all cases the URL will end with a number that can range from 1000 to 10000, right?
And you tell us that in all cases the URL wil end in the following way:
...........=nnnnnn, right?
It doesn't matter what the rest of the URL looks like as long as it ends with an equal sign and a number from 1000 to 10000 the method I showed you works.
q = InStrRev("thesite.com/userid=conf=123333", "=")
The above will set the variable q to the value 24 which is the position of the = sign to the left on the number 123333.
Now, if q is greater than 0 it must be the value 24, agreed?
So.....
s = Mid("thesite.com/userid=conf=123333", q + 1)
if q is 24 then q +1 is 25 which is the position of the number 1 in the value 123333, agreed?
The above will get the middle part of the string at position 25 which is the entire number 123333 and put it in the variable s.
Now if you think that doesn't work then I don't know what you want but it works exactly the way I am telling you it works and I believe I am interepting your request correctly. If I am not then tell me so.
-
Apr 19th, 2008, 02:20 PM
#16
Thread Starter
Addicted Member
Re: Need help replacing a url!!
Now it only adds 123333 -.-
-
Apr 19th, 2008, 02:27 PM
#17
Re: Need help replacing a url!!
It doesn't add anything.
Answer me this: am I interpeting your request correctly?
Answer me this: Does it not put the number 123333 in the variable s?
-
Apr 19th, 2008, 02:35 PM
#18
Thread Starter
Addicted Member
Re: Need help replacing a url!!
Yea i had put a wrong letter ( my fault )
it doesnt add anything :S
[edit]
Code:
i now have the script:
Private Sub Command1_Click()
Dim i As Integer
Dim s As String
For i = 0 To browser.Document.links.length - 1
If InStr(1, browser.Document.links.Item(i).href, "WEBSITEUR.COM/ID=") = 1 Then
s = browser.Document.links.Item(i).href
q = InStrRev("WEBSITEURL.COM/ID=", "=")
s = Mid("WEBSITEURL.COM/ID=", q + 1)
script.AddItem s
End If
Next i
End Sub
Private Sub Form_Load()
Dim i As String
browser.Navigate Text1.Text
End Sub
Private Sub script_DblClick()
browser.Navigate script
End Sub
Last edited by menzow; Apr 19th, 2008 at 02:41 PM.
-
Apr 19th, 2008, 02:42 PM
#19
Re: Need help replacing a url!!
 Originally Posted by menzow
Now it only adds 123333 -.-
I believe jmsrickland's is just showing you a hard coded sample,
I haven't tested this but it might look something like this,
Code:
If InStr(1, browser.Document.links.Item(i).href, "websiteurl.com/userID=") = 1 Then
s = browser.Document.links.Item(i).href
q = InStrRev(s, "=")
script.AddItem Mid$(s, q + 1)
End If
-
Apr 19th, 2008, 02:46 PM
#20
Thread Starter
Addicted Member
Re: Need help replacing a url!!
thanks Edgemeal!!!!
its working!! thank you soooo much
-
Apr 19th, 2008, 02:46 PM
#21
Re: Need help replacing a url!!
Edgemeal, that is exactly what I showed him in post #5, he just didn't pay any attention to it.
-
Apr 19th, 2008, 02:47 PM
#22
Re: Need help replacing a url!!
 Originally Posted by menzow
thanks Edgemeal!!!!
its working!! thank you soooo much
Well, thank you too! I guess I didn't help you, right?
-
Apr 19th, 2008, 02:50 PM
#23
Thread Starter
Addicted Member
Re: Need help replacing a url!!
 Originally Posted by jmsrickland
Edgemeal, that is exactly what I showed him in post #5, he just didn't pay any attention to it.
That didn't work -.-"
-
Apr 19th, 2008, 02:52 PM
#24
Thread Starter
Addicted Member
Re: [RESOLVED] Need help replacing a url!!
And now i have a new problem
it shows duplicated ID's ( 2 times )
becouse there is a
thewebsite.com/id=12312
and
thewebsite.com/id=conf=12312
-
Apr 19th, 2008, 02:54 PM
#25
Re: Need help replacing a url!!
 Originally Posted by jmsrickland
Edgemeal, that is exactly what I showed him in post #5, he just didn't pay any attention to it.
Ya I see it now.
-
Apr 19th, 2008, 02:57 PM
#26
Re: [RESOLVED] Need help replacing a url!!
And now he complains that post #5 doesn't work.
Geezz, some people you just can't get it accross to.
-
Apr 19th, 2008, 03:29 PM
#27
Re: [RESOLVED] Need help replacing a url!!
 Originally Posted by menzow
And now i have a new problem
it shows duplicated ID's ( 2 times )
becouse there is a
thewebsite.com/id=12312
and
thewebsite.com/id=conf=12312
I assume you don't want duplicates in the listbox, if so add this,
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Function FindItem(Lst As ListBox, strText As String) As Integer
FindItem = SendMessage(Lst.hWnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
End Function
and replace -> script.AddItem Mid$(s, q + 1) <- with,
Code:
If FindItem(script, Mid$(s, q + 1)) = -1 Then script.AddItem Mid$(s, q + 1)
-
Apr 19th, 2008, 03:49 PM
#28
Thread Starter
Addicted Member
Re: [RESOLVED] Need help replacing a url!!
Huh i get the error with :
Compile error:
Only comments can appear after End sub,End property or End function
Code:
Private Sub Form_Load()
Dim i As String
browser.Navigate Text1.Text
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Function FindItem(Lst As ListBox, strText As String) As Integer
FindItem = SendMessage(Lst.hWnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
End Function
End Sub
No matter where i put this i get that error :S
-
Apr 19th, 2008, 03:59 PM
#29
Re: [RESOLVED] Need help replacing a url!!
You have a function within a sub
Do it this way...
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Sub Form_Load()
Dim i As String
browser.Navigate Text1.Text
End Sub
Private Function FindItem(Lst As ListBox, strText As String) As Integer
FindItem = SendMessage(Lst.hWnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|