简体   繁体   English

从HTML代码C#中提取特定ID

[英]Pull specific IDs from HTML code C#

I am making a program that you can log into facebook, go to someone's wall and post on it. 我正在制作一个程序,您可以登录到Facebook,进入某人的墙并将其发布。 I have all of this working, if i manually enter in the ID that i go and find in the HTML for the textview box where you write the status and the Post button where you click to post. 如果我手动输入要输入的ID,然后在HTML中找到文本状态框(在其中输入状态)和“发布”按钮(在其中单击以发布),则我可以完成所有这些工作。 My problem is that the ID for this textbox and the post button changes every single time you go to the page or the page refreshes. 我的问题是,每次转到页面或页面刷新时,此文本框和发布按钮的ID都会更改。 So you cant just code in the ID to get it like this HtmlElement element = browser.Document.GetElementById("some-ID"); 因此,您不能像这样HtmlElement element = browser.Document.GetElementById("some-ID");仅在ID中进行编码来获取它HtmlElement element = browser.Document.GetElementById("some-ID"); I need to somehow parse the HTML code and pull out the specific IDs for the textview and the button every time the page refreshes. 我需要以某种方式解析HTML代码,并在每次页面刷新时为textview和按钮提取特定的ID。 I have looked into html agility pack and it hasn't really helped me any. 我研究了html敏捷包,它并没有真正帮助我。 Can anyone help? 有人可以帮忙吗?

EDIT Here is the line of code I am trying to get the ID out of for the text area where you post. 编辑这是我要获取您发布的文本区域的ID的代码行。 You can see that it is just a random garble of letters and some numbers at the end. 您会看到它只是结尾的随机乱码字母和一些数字。 It changes every time you load the page. 每次加载页面时,它都会更改。 And I haven't looked at the facebook api would it help any? 而且我还没有看过facebook api会有所帮助吗?

<DIV class="innerWrap"><TEXTAREA aria-expanded="false" onkeydown='Bootloader.loadComponents(["control-textarea"], function() { TextAreaControl.getInstance(this) }.bind(this)); ' id="ujkzdk454" class="DOMControl_placeholder uiTextareaAutogrow input mentionsTextarea textInput" title="Write something..." role="textbox" aria-owns="typeahead_list_ujkzdk453" name="xhpc_message" autocomplete="off" aria-autocomplete="list" placeholder="Write something..." aria-label="Write something...">Write something...</TEXTAREA></DIV></DIV></DIV><INPUT 

I agree you should probably be using the Facebook API but anyway, how about some thing like this with jquery? 我同意您可能应该使用Facebook API,但是无论如何,jquery这样的事情怎么样?

var textarea = $('textarea', '.innerWrap');
var button = $('.innerWrap').next('input');

and if you still want the ids 如果您仍然想要ID

var textareaId = textarea.attr('id')
var buttonId = button.attr('id') 

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

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