Parsing Splitting Website Text to Label-Textbox

Csyfer

New member
Joined
Jun 16, 2015
Messages
3
Programming Experience
5-10
HTML:
<html><head></head>

  <body> <div style="width:638px; margin-left:-1px;">
    <center><br /><img class="store_header" id="store_top" name="store_top" 

src="" /><div class="store_sub_header">
            <span class="yellow_glow_40">Some Text</span>
<div class="white_black_glow_24">
                

Date-Date</div>
</div>
<p>    </p></center>
<div>
         </div>
<div>
         </div><div class="yellow_glow_24">
                New 

Deals</div>
<div class="white_black_glow_18">
                New discounts</div>
<div class="white_black_glow_18">
                

Everyday of the week</div>
<div class="white_black_glow_18">
                Every weekend</div>
<div class="button_center">
                

<img class="green-button" src="" /><a class="button_gradient" href="">Learn More</a> <img class="green-button" src="" /></div>
</div>
<!--My Promo Box End--

><div class="promotion_block">
<div class="yellow_glow_24">
                What a day for summer</div>
<div class="white_black_glow_18">
        

        is back for a limited time</div>
<div class="white_black_glow_18">
                Join in!</div>
<div 

class="white_black_glow_18">
                Now through 10/25</div>
</div>
<!--Limited--></div>

<div class="free_copy">
<div 

class="white_black_glow_18">
                    Day ? Day</div>
<div class="yellow_glow_24">
                    MegaChung 

Bucks x1</div>
<div class="white_black_glow_18">
                    Use Code <span class="coupon_code">IMRDY1</span> 1/Account</div>
</body>
</html>

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'On Error Resume Next
        Dim StoreCode As String, StoreText As String, StoreDate As String
        MyWin = New WinHttp.WinHttpRequest
        MyWin.Option(WinHttpRequestOption.WinHttpRequestOption_EnableHttp1_1) = True
        MyWin.Option(WinHttpRequestOption.WinHttpRequestOption_EnableRedirects) = True
        MyWin.Option(WinHttpRequestOption.WinHttpRequestOption_EnableHttpsToHttpRedirects) = True
        Try
            MyWin.Open("GET", "C:/Parsing-Splitting.html", False)
            MyWin.SetRequestHeader("Host", "localhost")
            MyWin.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1")
            MyWin.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
            MyWin.SetRequestHeader("Connection", "keep-alive")
            MyWin.Send()
            A1 = MyWin.ResponseText

            '<div class="free_copy">
            '<div class="white_black_glow_18">
            ''                    Day-Day</div>
            '<div class="yellow_glow_24">
            '                    MegaChung x1</div>
            '<div class="white_black_glow_18">
            '                    Use Code <span class="coupon_code">IMRDY1</span> 1/Account</div>

            
            StoreText = ParseInfo(A1, "<div class=" & Chr(34) & "yellow_glow_24" & Chr(34) & ">", " x1</div>")
            StoreCode = ParseInfo(A1, "<span class=" & Chr(34) & "coupon_code" & Chr(34) & ">", "</span>")
            lblStoreItem.Text =  StoreText
            lblCode.Text = StoreCode

            MyWin.Abort()

        Catch ex As Exception
            Return
        End Try
    End Sub

This works perfectly as far as grabbing everything but unfortunetly where i try to grab StoreText it does not grab anything of it & i know it has to do with the fact the html has severl yellow_glow_24 div tags and i been trying to grab the text MegaChung x1...but iv'e tried everything i know to get around it any ideas or help please i been trying for almost a week now.
 
Missing ParseInfo function

VB.NET:
            StoreText = ParseInfo(A1, "<div class=" & Chr(34) & "yellow_glow_24" & Chr(34) & ">", " x1</div>")
            StoreCode = ParseInfo(A1, "<span class=" & Chr(34) & "coupon_code" & Chr(34) & ">", "</span>")

I'm trying to duplicate the issue but the ParseInfo function isn't included in the above code. Do I need to add a reference to some other COM object (other than WinHTTP)? Or is this a custom function that you wrote?

-E
 
Re: Parsing

I'm trying to duplicate the issue but the ParseInfo function isn't included in the above code. Do I need to add a reference to some other COM object (other than WinHTTP)? Or is this a custom function that you wrote?

-E

I forgot to add the function it goes in a module:

VB.NET:
   Function ParseInfo(ByVal Expression As String, ByVal DelimiterA As String, ByVal DelimiterB As String)
        On Error Resume Next
        Dim A As Integer, B As Integer
        A = 1
        While InStr(A, Expression, DelimiterA) > 0
            A = InStr(A, Expression, DelimiterA) + Len(DelimiterA)
            B = InStr(A, Expression, DelimiterB)
            ParseInfo = Mid$(Expression, A, B - A)
        End While
    End Function
 
I'm getting the following exception:
"The URL does not use a recognized protocol"
MyWin.Open("GET", "C:/Parsing-Splitting.html", False)

I created a copy of the HTML you pasted into Parsing-Splitting.html but I think WinHTTPRequest is expecting some sort of an HTTP protocol and not a local resource. Does this code run for you exactly as pasted above, or did you replace an HTTP URL with a local string here?

-E
 
parse

I'm getting the following exception:
"The URL does not use a recognized protocol"
MyWin.Open("GET", "C:/Parsing-Splitting.html", False)

I created a copy of the HTML you pasted into Parsing-Splitting.html but I think WinHTTPRequest is expecting some sort of an HTTP protocol and not a local resource. Does this code run for you exactly as pasted above, or did you replace an HTTP URL with a local string here?

-E

i replaced a url string with localhost
 
Back
Top