Home > DeveloperSection > Forums > How to get value from any tag in web browser control using wpf
Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    July-15-2013 8:28 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 4049  View(s)
Rate this:
HI Developers!

I have a whole web page source code in a string type variable.

These code is given below:-

<!DOCTYPE html>

<html lang="en" dir="ltr"

      class="">

  <head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">

    <title>Twitter / Authorize an application</title>

 

    <link href="https://abs.twimg.com/a/1373417125/tfw/css/tfw.bundle.css" media="screen" rel="stylesheet" type="text/css" />

    <!--[if (IEMobile) & (lt IE 9)]>

    <link href="https://abs.twimg.com/a/1373417125/tfw/css/tfw_iemobile.bundle.css" media="screen" rel="stylesheet" type="text/css" />

    <![endif]-->

 

 

 

    <style type="text/css">

      html { display:none; }

    </style>

    <noscript>

      <style type="text/css">

        html { display: block; }

      </style>

    </noscript>

    <!--[if IEMobile & lt IE 9]>

    <style type="text/css">

      html { display: block; }

    </style>

    <![endif]-->

  </head>

  <body class="oauth

 write

 signed-in

 tfw

 en

 logged-in

 

 

 noloki

">

 

    <div id="header" role="banner">

      <div class="bar">

        <h1 class="logo"><a href="https://twitter.com/home" class="alternate-context">Twitter</a></h1>

 

 

        <div id="session" role="navigation">

          <h2 class="current-user"><a href="https://twitter.com/xyz" title="Ankita Kumar">

            <img src="https://twimg0-a.akamaihd.net/profile_images/37880007865454313/7c577aeb3085dasf355dgf76f043c1cd09_mini.jpeg" alt="" width="24" height="24">

            <span class="name">ankita_yahoo</span>

          </a></h2>

          <div class="user-menu">

            <h3 class="session">User Management</h3>

            <ul class="session">

              <li class="new"><a href="/intent/tweet">New Tweet</a></li>

              <li class="settings"><a href="/settings">Settings</a></li>

              <li class="help"><a href="/help">Help</a></li>

 

                <li class="signout"><form action="/intent/session" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="delete" /><input name="authenticity_token" type="hidden" value="015cfb030df22330e517d50b0770c4dab7f3f89b" /></div>

                    <input id="referer" name="referer" type="hidden" value="/oauth/authorize" />

                    <input type="submit" class="textual link" value="Sign out">

                </form></li>

 

            </ul>

          </div>

        </div>

 

      </div>

    </div>

 

    <div id="bd" role="main">

 

<p class="action-information">You've granted access to ThisTweetControl!</p>

 

<div id="oauth_pin">

  <p>

    <span id="code-desc">Next, return this PIN to complete the authorization process:</span>

    <kbd aria-labelledby="code-desc"><code>6107346</code></kbd>

  </p>

</div>

 

 

 

    </div>

 

 

 

 

    <div class="footer" role="navigation"><div id="ft">

 

  <a href="https://twitter.com/home" class="return-link alternate-context">Go to Twitter</a>

 

  <a href="http://www.xyz.biz" class="supplemental-link alternate-context">Go to the ThisTweetControl homepage</a>

 

<p class="tip">You can revoke access to any application at any time from the <a href="https://twitter.com/settings/applications">Applications tab</a> of your Settings page.</p>

<p><small>By authorizing an application you continue to operate under <a href="https://twitter.com/tos">Twitter's Terms of Service</a>. In particular, some usage information will be shared back with Twitter. For more, see our <a href="https://twitter.com/privacy">Privacy Policy</a>.</small></p>

 

    </div></div>

 

 

    <script type="text/javascript" charset="utf-8">

        var twttr = twttr || {};

        twttr.form_authenticity_token = '015cfb03a75wdsfgdf6753dsfb0770c4dab7f3f89b';

        if (self == top) {

            document.documentElement.style.display = 'block';

        }

    </script>

 

    <script src="https://abs.twimg.com/a/14353417125/javascripts/loadrunner.js" data-main="tfw/intents/main" data-path="https://abs.twimg.com/a/1373417125/javascripts/modules" type="text/javascript"></script>

 

 

 

 

 

 

 

  </body>

</html>

In above line of code have a code tag <code>6107346</code> with some value and I need to get the numeric value in a variable.

thanks in advanced.



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-16-2013 12:00 AM

Hello Samuel!

If you use System.Windows.Controls.WebBrowser control then this should work, however it works on assumption that you only have one CODE tag:

var myTagValue = (wbBrowser.Document as mshtml.HTMLDocument)

                   .getElementsByTagName("CODE")

                   .OfType<mshtml.IHTMLElement>()

                   .First()

                   .innerText

You'll need to reference Internet Explorer's COM library: Microsoft HTML Object Library. getElementsByTagName returns you list of all matching tags, no matter where they are in HTML


Don't want to miss updates? Please click the below button!

Follow MindStick