How to Extract this?

Discussion in 'Visual Basic .NET' started by ronstylistic386, Aug 30, 2011.

  1. ronstylistic386

    ronstylistic386 Junior Member

    Joined:
    Mar 28, 2011
    Messages:
    198
    Likes Received:
    366
    Code:
    <div id="content"><div id="content-body">
    <div class="post-12 page type-page status-publish hentry" id="post-12">
    <h2><a title="Home" href="http://s1.wepn.info/" rel="bookmark">Home</a></h2>
    <h4><a href="error-logs-collection">Error Logs Collection</a></h4>
    <h5>wePN is a revolutionary free VPN service.</h5>
    <p><strong>Why wePN?</strong></p>
    <ul>
    <li>Free of charge</li>
    <li>Multi-platform support</li>
    <li>No registration required</li>
    <li>Unlimited time and bandwidth usage</li>
    <li>Encrypted, safe and uncensored</li>
    <li><span style="color: green;">Now with HTTPS!</span> <strong><a href="https://ssl.wepn.info">https://ssl.wepn.info</a></strong></li>
    <li><span style="color: green;">PPTP and OpenVPN support!</span> <strong><a href="guides">Click here for details.</a></strong></li>
    </ul>
    <p>Browse the Internet with freedom and speed now!<br/>
    <span style="color: blue;">wePN will NOT provide VPN service to users in Mainland China.</span><br/>
    Contact Us: <strong>cs(at)wepn(dot)info</strong></p>
    <h5>Server 2(PPTP only): <a href="http://s2.wepn.info">http://s2.wepn.info</a> | <a href="https://ssl.wepn.info">https://ssl.wepn.info</a></h5>
    42/100 Server 1 PPTP users.<br/>46/75 Server 1 OpenVPN(UDP) users.<br/>2/25 Server 1 OpenVPN(TCP) users.<br/>27/100 Server 2 PPTP users.<br/><br/>wePN OpenVPN Client: <a href="../../vpn/wePN%20SSL_latest.php"><b>Download</b></a> (OpenVPN config files included)<br/>OpenVPN Config Files: <a href="../../vpn/config.zip"><b>Download</b></a> (Windows client version 2.2 or later required)<br/><span style="color: blue;">Accounts can be used for both PPTP and OpenVPN but NOT across servers.</span><br/><span style="color: red;">Please connect to IP addresses of the servers. Domain names would NOT work.</span><br/><br/>Server: <img src="/vpn/tick.gif"/>58.177.252.105 (<img src="/vpn/cross.gif"/>s1.wepn.info)<br/>Username: [COLOR="DarkRed"]13305525[/COLOR]<br/>Password: [COLOR="DarkRed"]23584715[/COLOR]<br/><br/>Please log in within 5 minutes.<br/><br/>Thank you for using wePN.<br/><a href="./guides/"><b>Guides</b></a> | <a href="./support/"><b>Support</b></a>
    </div>
    
    Hello BHW

    I need help on how to extract this username and password(color red) that is from a webpage source code, I only want to know on how to extract it?

    Any help guys?
     
    Last edited: Aug 30, 2011
  2. scriptomania

    scriptomania Junior Member

    Joined:
    Dec 28, 2010
    Messages:
    127
    Likes Received:
    250
    Occupation:
    A full time pirate at sea
    Location:
    The European capital of politics
    Doesn't VB have some type of webparsing library?
    Regex (for username string):
    Code:
    <br/>Username:\s(.*?)<br/>
    Regex (for pass string):
    Code:
    Password:(.*?)<br/>
     
    • Thanks Thanks x 1
  3. scriptomania

    scriptomania Junior Member

    Joined:
    Dec 28, 2010
    Messages:
    127
    Likes Received:
    250
    Occupation:
    A full time pirate at sea
    Location:
    The European capital of politics
    Regular expressions.... Or regex. A simple text processor. VB supports regex by default... Not the best solution for webparsing though, thats why I was wondering about some proper parsing libraries for VB. No idea since I dont use VB at all.
     
    • Thanks Thanks x 1
  4. Hydrogen

    Hydrogen Newbie

    Joined:
    Dec 30, 2009
    Messages:
    39
    Likes Received:
    23
    Occupation:
    Co-Owner of AdvertMarketing
    I normally don't release code but Hell why not, guess i'll embrace a bit of OpenSource mentality for the night :D

    Here is a simple function I wrote that I use to do all my web parsing.

    Code:
        Private Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String)
            Dim istart As Integer = InStr(haystack, needle)
            If istart > 0 Then
                Dim istop As Integer = InStr(istart, haystack, needle_two)
                If istop > 0 Then
                    Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
                    Return value
                End If
            End If
            Return Nothing
        End Function
    
    in this particular case lets assume you loaded this html from httpwebrequest, and are storing it in responseData variable.

    Code:
    ....
    Dim responseData as string= responseStream.ReadToEnd()
    
    Dim Username as string = GetBetween(responseData, "<br/>Username: ", "<br/>")
    Dim Password as string = GetBetween(responseData, "<br/>Password: ", "<br/>")
    
    Now of course RegEX would be the best way to get things done and more reliable as this particular solution does have some drawbacks.

    take for instance if this user/pass was in a table like this
    Code:
    <table width="25%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>USERNAME</td>
        <td>PASSWORD</td>
      </tr>
      <tr>
        <td>13305525</td>
        <td>23584715</td>
      </tr>
    </table>
    
    there is no way I could use this function to return back the username and password as what this does is finds the text between two unique strings.

    so since Username and Pass both have a <td> </td> 'ONLY surrounding it I couldn't get the user and pass from it using this method, I'd have to figure out something else to get them.

    I hope this however helps you in anyway possible.
     
    • Thanks Thanks x 2
  5. ronstylistic386

    ronstylistic386 Junior Member

    Joined:
    Mar 28, 2011
    Messages:
    198
    Likes Received:
    366
    thank you for your replies guys.. thanks given