0

我正在尝试从 twitter 页面读取值。页面源如下所示

 <!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>

我正在尝试将“PIN”的值输入到我的 C# winform 应用程序中。意思是下一行中代码标记之间的值

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

我已经尝试了下面的代码。但这不起作用,因为 PIN 包含在 div 标签中并且没有 id。请帮助从 html 网页获取 PIN 的值。谢谢

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

2 回答 2

1

为什么不尝试某种 HTML 解析器并在您的案例代码中的特定标记内传递值

这是可用于 c# 应用程序的良好 html 解析器的链接。

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();
于 2012-05-10T04:17:53.850 回答
0

尝试

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

代替

string verifier = browser.TextField(Find.ById("code-desc")).Value
于 2012-05-10T04:20:57.133 回答