Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > How to grab text from a source based on before and after strings


Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2005, 02:11 PM
ixparaxi ixparaxi is offline
Newcomer
 
Join Date: Jan 2005
Posts: 12
Question 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.
Reply With Quote
  #2  
Old 09-06-2005, 04:51 PM
jlm jlm is offline
Regular
 
Join Date: Aug 2005
Location: Very Far from George Bush
Posts: 84
Default

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.
__________________
JLM
Posting Guidelines
Reply With Quote
  #3  
Old 09-06-2005, 05:15 PM
ixparaxi ixparaxi is offline
Newcomer
 
Join Date: Jan 2005
Posts: 12
Default

I've been searching forever... What you provided didn't get me anywere, but thanks...
Reply With Quote
  #4  
Old 09-06-2005, 06:58 PM
TeraBlight's Avatar
TeraBlight TeraBlight is offline
Captain Convoluted

* Expert *
 
Join Date: Jun 2005
Posts: 1,918
Default

The InStr() function should be all you need to locate the start and end position of the name. Then, you can use Mid$() to get hold of the name itself

A forum search for InStr should find you some sample code. E.g. iceplug discusses something rather similar here: http://www.xtremevbtalk.com/showthread.php?p=996785
__________________
"To learn without thinking is to labour in vain" - Confucius
Reply With Quote
  #5  
Old 09-06-2005, 07:00 PM
cereal_1 cereal_1 is offline
Regular
 
Join Date: Aug 2004
Posts: 54
Default

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.
Reply With Quote
  #6  
Old 09-06-2005, 11:40 PM
ixparaxi ixparaxi is offline
Newcomer
 
Join Date: Jan 2005
Posts: 12
Default

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!
Reply With Quote
  #7  
Old 09-06-2005, 11:46 PM
TeraBlight's Avatar
TeraBlight TeraBlight is offline
Captain Convoluted

* Expert *
 
Join Date: Jun 2005
Posts: 1,918
Default

Have a look here
__________________
"To learn without thinking is to labour in vain" - Confucius
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->