简体   繁体   中英

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. 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. 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. So you cant just code in the ID to get it like this 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. I have looked into html agility pack and it hasn't really helped me any. 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. 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?

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

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

and if you still want the ids

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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