简体   繁体   English

通过HtmlUnit在Facebook上发布

[英]Post on Facebook via HtmlUnit

I looking for a "method" to post a message on facebook using HtmlUnit. 我正在寻找一种使用HtmlUnit在Facebook上发布消息的“方法”。 I'd like to go to the wall page, and fill the text box: 我想转到墙上的页面,并填写文本框:

HtmlTextInput text = (HtmlTextInput) page.getElementById(textBoxId);
text.setTextContent("Hello!");

I want to "click" on the Post button, but i can't figure out the way to select the button element and perform the action. 我想“单击”“发布”按钮,但是我不知道选择按钮元素和执行操作的方式。 Is there a way to do so? 有办法吗?

Here's an explicative image: 这是一个解释性图像:

If an element doesn't contain an id attribute you can still get it using XPath. 如果一个元素不包含id属性,您仍然可以使用XPath来获取它。 The HtmlUnit way of using XPath is by means of the getFirstByXPath and getByXPath methods. HtmlUnit使用XPath的方式是通过getFirstByXPathgetByXPath方法。

A short and over simplified example would be: 一个简短而过度简化的示例是:

page.getFirstByXPath("//button[text()='Post']");

As a side note, you might be more interested in using the Facebook API rather than webscraping Facebook, which, by the way, is very likely to be against their terms of service. 附带说明一下,您可能对使用Facebook API感兴趣,而不是对Facebook进行网络抓取,顺便说一句,这很可能违反了他们的服务条款。

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

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