通过Web浏览器通过ID获取元素并显示在标签中 [英] Get element by ID from webbrowser and show in label

查看:203
本文介绍了通过Web浏览器通过ID获取元素并显示在标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了一个问题.我想在我的Windows应用程序表单上的标签上显示来自网页的文本.这是检查元素"代码:

So I a having a issue.. I want to show the text from a webpage, on the label on my Windows Application Form. Here is the "Inspect Element" code:

<ul id="userInfoNav">
<li>Rank: <span class="value">Sivilist</span></li>
<li>Bosted: <span class="value">Oslo</span></li>
<li>Gjeng: <span class="value">Ingen</span></li>
<li>Penger: <span id="money_hand" class="value">16,000 kr</span></li>
<li>Kuler: <span class="value">0 stk</span></li>

我尝试使用:

web.Document.GetElementById("userInfoNav").InvokeMember("Value", label1.Text);

但是它什么也没做..

文本也可以不时更改..

The texts can change from time to time also..

推荐答案

获取外部文本:

statsTextBox.Text = web.Document.GetElementById("userInfoNav").OuterText;

并在执行代码之前检查ID是否存在:

And to check if the ID exist, before executing the code:

HtmlElement htmlelement = web.Document.GetElementById("userInfoNav");
            if (htmlelement == null)
            {
                return;
            }
            else
            {
                statsTextBox.Text = web.Document.GetElementById("userInfoNav").OuterText;
            }

这篇关于通过Web浏览器通过ID获取元素并显示在标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆