简体   繁体   English

c#从隐藏输入中获取值

[英]c# get value from hidden input

Soo ive been trying to get the value from a hidden input and innertext from a span on a website (Note that i dont have access to edit the html code) Soo 我一直试图从网站上的跨度中的隐藏输入和内部文本中获取值(请注意,我无权编辑 html 代码)

Code from website:来自网站的代码:

<input type="hidden" name="hidv" value="1582912961">
<span class="valo">0.888</span>

i could use a code similar to this but dont know the correct use of it:我可以使用与此类似的代码,但不知道如何正确使用它:

    label5.Text = webBrowser2.Document.GetElementById("hidv").InnerText;
    label6.Text = webBrowser2.Document.GetElementById("valo").InnerText;

First I'd put an ID on the input tag首先,我会在输入标签上放一个 ID

<input id="myId" type="hidden" name="hidv" value="1582912961">

Then you could use JS, jQuery, etc, to select the value.然后你可以使用 JS、jQuery 等来选择值。

$('#myId').val();

$('input[name=hidv]').val()

also just a note Document.GetElementById requires an Id.也只是一个注释Document.GetElementById需要一个 Id。 Otherwise, you could've done Document.GetElementsByClassName("valo") if you wanted to use the class name instead of an Id attribute.否则,如果您想使用类名而不是 Id 属性,您可以完成Document.GetElementsByClassName("valo")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM