harry
harry

Reputation: 51

Reading of the value between HTML tags into C# winform application

I am trying to read a value from a twitter page.The page source looks like this

 <!DOCTYPE html>
<html lang="en">
  <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>

  ...........

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

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

<div id="oauth_pin">
  <p>
    <span id="code-desc">Next, return to yourapp and enter this PIN to complete the authorization process:</span>
    <kbd aria-labelledby="code-desc"><code>58643144</code></kbd>
  </p>
</div>


    </div>

   ..............

  </body>
</html>

I am trying to get the value of 'PIN' into my C# winform application.Means,the value between code tags in the below line

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

I have tried the below code.But this is not working because the PIN is enclosed in div tags and don't have an id. please help to get the value of PIN from the html web page. Thanks

string verifier = browser.TextField(Find.ById("code-desc")).Value

Upvotes: 0

Views: 1374

Answers (2)

COLD TOLD
COLD TOLD

Reputation: 13579

why not try some kind of HTML parser and prase for value inside specific tag in your case code

here is a link to a good html parser that can be used for c# apps.

http://htmlagilitypack.codeplex.com/

StringBuilder codew = new StringBuilder();
foreach (HtmlAgilityPack.HtmlTextNode node in
      doc.DocumentNode.SelectNodes("//code/text()"))
{
    codew.Append(node.Text.Trim());
}
string foundcode = sb.ToString();

Upvotes: 1

Mamta D
Mamta D

Reputation: 6450

Try

string verifier = browser.TextField(Find.ById("code-desc")).Text 

instead of

string verifier = browser.TextField(Find.ById("code-desc")).Value

Upvotes: 0

Related Questions