我写了这个代码:2.9的HtmlUnit罐子张贴评论
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author user
*/
public class YouTubeComment {
public static void main(String[] args) {
boolean f = YouTubeLogin.login();
try {
if (f) {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setRedirectEnabled(true);
webClient.setJavaScriptEnabled(false);
HtmlPage firstPage = webClient.getPage("http://www.youtube.com/watch?v=kqDacBDoVM4&feature=related");
List<HtmlForm> forms = new ArrayList();
forms = (List<HtmlForm>) firstPage.getForms();
HtmlForm form = firstPage.getForms().get(1);
HtmlTextArea commentArea = (HtmlTextArea)form.getTextAreaByName("comment");
commentArea.setText("good");
HtmlSubmitInput submitButton =(HtmlSubmitInput)form.getInputByName("");
HtmlPage pageAfterPost = (HtmlPage) submitButton.click();
} else {
System.out.println("Sorry..! Login is not successful");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
这个应用程序可以登录到YouTube帐户的用户名和密码。
我想写一些代码,在成功登录后发布评论。
请帮忙。
您能否至少张贴您想发表评论的网址? – 2012-04-14 08:42:54
@Guillaume Polet,http://www.youtube.com/watch?v = kqDacBDoVM4&feature = related – user1319054 2012-04-14 08:44:24
请原谅我的要求,但有没有一些您想要这样做的正当理由?如果这只是一个巨大的垃圾邮件引擎,我不敢提供帮助。 – theJollySin 2012-04-15 01:50:08