 |

09-06-2005, 02:11 PM
|
|
Newcomer
|
|
Join Date: Jan 2005
Posts: 12
|
|
How to grab text from a source based on before and after strings
|
I'm tryin to write a program to collect names from an online game that I run. It's called Ultima Online and I run an Emulated Server on UOGateway. The people currently logged on is sent to a php site, its a script that comes with RunUO, the online game emulator. I want to be able to dispatch the list of players to a text file and always have them, so I know who has logged on my server, and I have a FULL player list of everysingle person ever on.
So what I want this to do is, open internet explorer, go to the website, and based on the source code, give me the name.
The part of the source(there are about 10 names per page) looks like this
"&sn=RavingFighter&id"
Now my question... How do I make VB6 go to this site, view the source(preferably without opening it, but its not important) and grab the string inbetween &sn= and &id? It would have to repeat itself 10 times, or until the end of the source is reached, then dispatch all of the names either to a listbox on a vb program, or to a text file in the programs directory.
Thanks a million! Please ask any questions that would help anyone help me
-Para
P.S.
I found this after my post, while i was still searching for the answer.
http://www.vb-helper.com/howto_divide_text.html
That pertains to what I am doing, the only problem is, I don't understand how I'm gonna get the text from the source code... From &sn= to &id... Thanks for any help!
|
Last edited by ixparaxi; 09-06-2005 at 02:30 PM.
|

09-06-2005, 04:51 PM
|
|
Regular
|
|
Join Date: Aug 2005
Location: Very Far from George Bush
Posts: 84
|
|
Code:
MsgBox (Inet1.OpenURL("http://www.whatever.com"))
ofcourse it doesnt have to be a msgbox, you could use "text1.text =" or anything that pulls it as a string value. you'll need to add an inet control to your form, it doesnt load the website really, well it does, in the background but not displaying it. thats what you asked about i think.
for the searching/parsing, search the forum there is tons and tons of string manipulation posts that I'm sure will get you started.
|
|

09-06-2005, 05:15 PM
|
|
Newcomer
|
|
Join Date: Jan 2005
Posts: 12
|
|
|
I've been searching forever... What you provided didn't get me anywere, but thanks...
|
|

09-06-2005, 06:58 PM
|
 |
Captain Convoluted
* Expert *
|
|
Join Date: Jun 2005
Posts: 1,918
|
|
__________________
"To learn without thinking is to labour in vain" - Confucius
|

09-06-2005, 07:00 PM
|
|
Regular
|
|
Join Date: Aug 2004
Posts: 54
|
|
Code:
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long _
, ByVal szURL As String _
, ByVal szFileName As String _
, ByVal dwReserved As Long _
, ByVal lpfnCB As Long) As Long
Const TEMPFILE As String = "C:\SourceCode.txt"
'Use Function to call API
Private Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
If Not DownloadFile(txtURL.Text, TEMPFILE) Then
MsgBox "Failed to get source code"
Exit Sub
End If
'Open the contents up into txtSource.txt
Open TEMPFILE For Input As #1
Text1.Text = Input$(LOF(1), #1)
Close #1
'delete the temp file if you want
Kill TEMPFILE
End Sub
I just tried this code out and it works pretty good, it uses an API. You just need a text box for the Url (txtURL) and one to display the code (text1). You could put the data into a string and parse it from there if you'd like.
|
|

09-06-2005, 11:40 PM
|
|
Newcomer
|
|
Join Date: Jan 2005
Posts: 12
|
|
|
Thank you very much for that code! Now all i'm having trouble with is, I dont know the full string! I only know the first part and the last part, and i want the part thats between those two.
Thanks!
|
|

09-06-2005, 11:46 PM
|
 |
Captain Convoluted
* Expert *
|
|
Join Date: Jun 2005
Posts: 1,918
|
|
__________________
"To learn without thinking is to labour in vain" - Confucius
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|