Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > VB6 parsing HTML to get text entered into a forum post


Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2010, 01:26 PM
StealthRT's Avatar
StealthRT StealthRT is offline
Contributor
 
Join Date: Aug 2002
Posts: 702
Question VB6 parsing HTML to get text entered into a forum post

Hey all, i am using VB6 to check out a forum website and get the text from EACH poster. This is how the HTML is layied out for each posting from each user.
Code:
    <tr valign="top">
	<td width="175" style="border-right: 1px solid rgb(238, 238, 238); border-left: 1px solid rgb(238, 238, 238); border-width: 0px 1px; 
border-style: none solid; border-color: -moz-use-text-color rgb(238, 238, 238);" class="alt2">
		<div id="postmenu_4486861">				
			<a href="http://www.link.org/forum/members/34272.html" class="bigusername" rel="nofollow">Tod Whnner</a>
		</div>
		<div class="smallfont">Forum Member</div>
		<div class="smallfont">
			&nbsp;<br>
			<div>Join Date: May 2007</div>
			<div>Location: Somewhere, GA</div>
			<div>Likes: Computers</div>				
				<div><span id="repdisplay_4486861_34272">
<img border="0" alt="Tod Whnner" src="http://www.link.org/forum/images/reputation/reputation_balance.gif" class="inlineimg"></span></div>
				<div class="smallfont">Feedback Score: 1 reviews</div>
				<div></div>
			</div>
	</td>	
	<td style="border-right: 1px solid rgb(238, 238, 238);" id="td_post_4486861" class="alt1">
			<!-- icon and title -->
			<div class="smallfont">
				<img border="0" alt="Default" src="http://www.link.org/forum/images/icons/icon1.gif" class="inlineimg" title="Default">
				<strong>Re: Need help with something</strong>
			</div>
			<hr size="1" style="color: rgb(238, 238, 238); background-color: rgb(238, 238, 238);">
			<!-- / icon and title -->

		<!-- message -->
		<div id="post_message_4486861">
			This is the post where i need to get the text from here
		</div>
		<!-- / message -->
	</td>
    </tr>
I am trying to get the users name "Tod Whnner" and "This is the post where i need to get the text from here" from each post but the problem i am runnning into is that each post has a different number for it (ie. post_message_4486861) so i can not go by the div ID and keep moving until it doesnt find one anymore.

The code below was taken from a post here http://www.xtremevbtalk.com/showpost...50&postcount=5
Code:
     Dim strData As String
     Dim strForum As String
     Dim strStrong As String
     Dim strNotStrong As String
     Dim strF As String
     Dim lngPos As Long
     Dim lngPos1 As Long
     Dim lngStart As Long
     Dim boDone As Boolean

     txtResults.Text = ""
     strForum = "valign=""top"""
     strStrong = "<div id=""post_message_"">"
     strNotStrong = "</div>"
     strData = Inet1.OpenURL("http://www.link.org/forum/f77/need-local-streamwood-120k-tuneup-expert-please-388717/")
     
     If Inet1.StillExecuting = True Then
     Do
          Loop Until Inet1.StillExecuting = False
     End If
     lngStart = 1
     Do
    '
    ' Find the next record with "Class = "alt1Active"
    ' if found, starting from where that ends, look for
    ' <strong> which marks the start of the Forum Name
    ' then look for </strong> which marks the end of
    ' the Forum Name. Move the text between the two
    ' positions into the textbox.
    ' Set the search start point to just after the name
    ' and repeat until we can't find a "Class = "alt1Active"
    '
    lngPos = InStr(lngStart, strData, strForum)
    If lngPos <> 0 Then
        lngPos = InStr(lngPos + Len(strForum), strData, strStrong)
        If lngPos <> 0 Then
            lngPos1 = InStr(lngPos, strData, strNotStrong)
            If lngPos1 <> 0 Then
                strF = Mid(strData, lngPos + Len(strStrong), lngPos1 - (lngPos + Len(strStrong)))
                txtResults.Text = txtResults.Text & strF & vbCrLf
            End If
        End If
    Else
        boDone = True
    End If
    lngStart = lngPos1 + Len(strNotStrong)
    Loop Until boDone = True
Any help would be great!

David
Reply With Quote
  #2  
Old 07-30-2010, 11:31 PM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,921
Default

Try
Code:
 strStrong = "<div id=""post_message_"
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #3  
Old 07-31-2010, 02:29 AM
StealthRT's Avatar
StealthRT StealthRT is offline
Contributor
 
Join Date: Aug 2002
Posts: 702
Default

Quote:
Originally Posted by DougT View Post
Try
Code:
 strStrong = "<div id=""post_message_"
Hey Dougt, i tried that but it still came up with the same problem. Seems
Code:
lngPos = InStr(lngPos + Len(strForum), strData, strStrong)
        If lngPos <> 0 Then
equals to 0.

David
Reply With Quote
  #4  
Old 07-31-2010, 04:41 AM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,921
Default

Unfortunately I'm getting a 404 Not Found when I try to access the URL. I'd check that lngPos has a sensible value after the search for strForum (ie it's found the one you were expecting) also check that the page you've actually gone to is the right one! (a Debug.Print strData will show you if you're where you think you are.
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 2 (0 members and 2 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:

Powered by liquidweb