Tuesday 9 January 2018 photo 1/1
|
Htmlunit Login Facebook ->>> http://urlin.us/bze7i
Not the answer you're looking for? Browse other questions tagged java html facebook cookies post or ask your own question. The following page and code should guide you: final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage(" final HtmlForm form = page1.getFormByName("loginform"); final HtmlSubmitInput button = form.getInputsByValue("Log in"); final HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("jonjon.com"); final HtmlTextInput textField = form.getInputByName("pass"); textField.setValueAttribute("ahhhh"); final HtmlPage page2 = button.click(); shareimprove this answer edited Feb 17 '10 at 23:39 answered Feb 17 '10 at 23:33 Jon 39.9k25110146 1 Thanks for the answer. .. Stack Overflow Questions Developer Jobs Tags Users current community help chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. .csdn .net /zstucc/article/details/ 39250903 // 2. more stack exchange communities company blog Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Log In Sign Up . more stack exchange communities company blog Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Log In Sign Up . Stack Overflow Questions Developer Jobs Tags Users current community help chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. Try switching it off as it shouldn't be necessary for login: webClient.setJavaScriptEnabled(false); shareimprove this answer answered Jan 21 '11 at 13:08 Pablojim 5,90773461 I have tried this but could not get logged into facebook. –Jon Feb 18 '10 at 6:53 And how do you get returned data, like session token, with this? –Ixx May 6 '12 at 20:42 it is showing some sort of exceptions when i used the above code.Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[form] attributeName=[name] attributeValue=[UIFullPageContainer] what the error in my code.Plz help me –lulu Apr 24 '14 at 16:10 How to use it in Android ??? –Iman Marashi Jul 19 '17 at 20:04 add a comment up vote 11 down vote There are some problems in your code is that loginform is not the form name but the form ID the submit button value i Log In type of password field is HtmlPasswordInput so: final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage(" final HtmlForm form = (HtmlForm) page1.getElementById("loginform"); final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0); final HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("jonjon.com"); final HtmlPasswordInput textField2 = form.getInputByName("pass"); textField2.setValueAttribute("ahhhh"); final HtmlPage page2 = button.click(); shareimprove this answer answered Feb 29 '12 at 7:52 Luca 19516 thanks for the code. helped me in resolving the errors with earlier verison –Anoop Isaac Jan 1 '13 at 0:34 add a comment Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. I get page2 as facebook.com/?sk=welcome. Join Stack Overflow to learn, share knowledge, and build your career. I've got the below code so far that downloads the home html page into a String but don't know how to send the email and password to log into Facebook? Also will the Java program need to handle cookies returned to remain logged in? public static void main(String[] args) throws Exception { URL url = new URL(" URLConnection yc = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc .getInputStream())); String inputLine; String allInput = ""; while ((inputLine = in.readLine()) != null) { allInput += inputLine + "rn"; } System.out.println(allInput); in.close(); } } Update: I've tried the below code using htmlUnit however I get the following exception: Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[form] attributeName=[name] attributeValue=[loginform] at com.gargoylesoftware.htmlunit.html.HtmlPage.getFormByName(HtmlPage.java:588) Anyone know why this is? final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage(" final HtmlForm form = page1.getFormByName("loginform"); final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Login").get(0); final HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("jonjon.com"); final HtmlTextInput textField2 = form.getInputByName("pass"); textField2.setValueAttribute("ahhhh"); final HtmlPage page2 = button.click(); java html facebook cookies post shareimprove this question edited Feb 17 '10 at 23:59 asked Feb 17 '10 at 23:29 tree-hacker 1,90172637 But i'm getting some exceptions like Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/protocol/ProtocolSocketFactory. How to best tell him to stop? If I generate a random symmetric matrix, what's the chance it is positive definite? How do I get other players to ask about my backstory? What is the smallest geological change possible to make human evolution untraceable? Dealing with aggressive student suspected to be cheating Is it possible that evolution brought human kind morality? EValuate a limit at infiniy How do I negotiate more "Man" time for myself without offending my partner? The Ultimate Typo The use of T[] as a template parameter Protection of shell command with string variable When reading papers, what's the most convenient way to check a citation without disrupting the reading process? How to partially extract zipped huge plain text file? How to determine the saturation level when an opamp schmitt trigger starts worknig? Writing a polynomial as a product of irreducible elements Is Sam Gamgee an orphan? more hot questions question feed lang-java . asked 6 years, 11 months ago viewed 3,734 times active 6 years, 11 months ago Blog Take the 2018 Developer Survey Linked 8 How to log into Facebook programmatically using Java? 3 Cannot login programmatically to facebook using htmlunit Related 4934Is Java “pass-by-reference" or “pass-by-value"?1638Does finally always execute in Java?2191In Java, difference between package private, public, protected, and private1626How do I call one constructor from another in Java?2669How do I generate random integers within a specific range in Java?1430Breaking out of nested loops in Java1285Comparing Java enum members: == or equals()?2277How to convert a String to an int in Java?2412Creating a memory leak with Java1493How does Facebook disable the browser's integrated Developer Tools? Hot Network Questions Could you strap shotguns to the back of a centaur to be fired during a charge? Why do different elements have different number of isotopes? EValuate a limit at infiniy Why was Harry Truman chosen to be Vice President in 1944? If a photoshoot doesn't represent my best work, should I offer to reshoot? How should I respond to questions asked before being allowed to enter the United States? What makes the Mauritius Passport so valuable? The use of T[] as a template parameter Is there a way to safely have exposed electrical wires? Why Google Translate translate back not same as the first time translate? Is this a low complexity region in our human genome? Can working on a mobile app with bad reviews affect my career? Is there a function that grows faster than exponentially but slower than a factorial? Collection of all configurable products (which has children) Kodi wont let me access Ubuntu or terminal How should a student's inefficient calculation be pointed out? Protection of shell command with string variable Equation numbers do not align to rightmost in beamer Hugely important database replete with errors Is Predator ever called Predator in any of the films? ssh - why can I login with partial passwords? Fourier transform using properties (exam exercise I couldn't solve) Is it possible that evolution brought human kind morality? Why was there a robot in Rocky IV? more hot questions question feed lang-java . // Most browsers manage to interpret the JS even with some kind of // errors // but HtmlUnit is a bit inflexible in that sense. Email Sign Up or sign in with Google Facebook How to log into Facebook programmatically using Java? Ask Question up vote 8 down vote favorite 4 I'm trying to write a Java program that can automatically log into Facebook. Join Stack Overflow to learn, share knowledge, and build your career. asked 7 years, 10 months ago viewed 27,606 times active 3 years, 8 months ago Blog Take the 2018 Developer Survey Linked 1 How to login Facebook using Java code? 0 HttpsURLConnection and POST 3 Using HTMLUnit to log into Facebook programmatically using Java -3 How to programmatically log in to a website which asks captcha using java? 0 Playing songs in java from a URL 0 Facebook login with HTTPSUrlConnection pure, without an API 0 Logging onto a website through java 0 HTMLUnit/Java - Form is not found Related 4934Is Java “pass-by-reference" or “pass-by-value"?3339How to horizontally center a in another ?2191In Java, difference between package private, public, protected, and private1626How do I call one constructor from another in Java?2669How do I generate random integers within a specific range in Java?3674How to check whether a checkbox is checked in jQuery?1453How to avoid Java code in JSP files?2277How to convert a String to an int in Java?2412Creating a memory leak with Java1493How does Facebook disable the browser's integrated Developer Tools? Hot Network Questions std::isinvocable is false but std::invoke works Why is it so inefficient to generate electricity by absorbing heat? 'Diagonalization' of Jordan block Keep virtual layer up to date How "scrambled" is the data on a RAID5 disk? Does a 2100W angle grinder need an earth pin? Spectre/meltdown on a GPU How suitable is "" for "priest"? Coworker scans my body. rev2018.1.8.28313 . If I enable javascript then I get the warning WARN: (HtmlScript.java:472): Script is not JavaScript (type: application/ld+json, language: ). Stack Overflow works best with JavaScript enabled .. Not the answer you're looking for? Browse other questions tagged java javascript html facebook login-script or ask your own question. It's back! Take the 2018 Developer Survey today . ( Exception class=[com.gargoylesoftware.htmlunit.ScriptException] com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "length" from undefined ( What am I doing wrong? java javascript html facebook login-script shareimprove this question edited May 23 '17 at 12:04 Communityf 11 asked Jan 21 '11 at 9:30 Robz 76111228 add a comment 1 Answer 1 active oldest votes up vote 1 down vote accepted It looks like htmlunit doesn't like some of the javascript. Stack Overflow Questions Jobs Developer Jobs Directory Salary Calculator Help Mobile Stack Overflow Business Talent Ads Enterprise Company About Press Work Here Legal Privacy Policy Contact Us Stack Exchange Network Technology Life / Arts Culture / Recreation Science Other Stack Overflow Server Fault Super User Web Applications Ask Ubuntu Webmasters Game Development TeX - LaTeX Software Engineering Unix & Linux Ask Different (Apple) WordPress Development Geographic Information Systems Electrical Engineering Android Enthusiasts Information Security Database Administrators Drupal Answers SharePoint User Experience Mathematica Salesforce ExpressionEngine Answers Stack Overflow em Portugus Blender Network Engineering Cryptography Code Review Magento Software Recommendations Signal Processing Emacs Raspberry Pi Stack Overflow Programming Puzzles & Code Golf Stack Overflow en espaol Ethereum Data Science Arduino Bitcoin more (26) Photography Science Fiction & Fantasy Graphic Design Movies & TV Music: Practice & Theory Worldbuilding Seasoned Advice (cooking) Home Improvement Personal Finance & Money Academia Law more (16) English Language & Usage Skeptics Mi Yodeya (Judaism) Travel Christianity English Language Learners Japanese Language Arqade (gaming) Bicycles Role-playing Games Anime & Manga Puzzling Motor Vehicle Maintenance & Repair more (32) MathOverflow Mathematics Cross Validated (stats) Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more (10) Meta Stack Exchange Stack Apps API Data Area 51 Blog Facebook Twitter LinkedIn site design / logo 2018 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. WebClient webClient = new WebClient(); HtmlPage page1 = webClient.getPage(" HtmlForm form = page1.getForms().get(0); HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Login").get(0); HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("bobsmith.com"); HtmlPasswordInput textField2 = form.getInputByName("pass"); textField2.setValueAttribute("ladeeda"); HtmlPage page2 = button.click(); However, whenever I attempt to log into facebook with correct email and password, I run into two problems: SEVERE: Job run failed with unexpected RuntimeException: TypeError: Cannot find function addImport in object [object]. In the en I get page2 as facebook.com/login.php?loginattempt=1&lwv=110. WILL HtmlUnitHttpclientJsoup htmlunithttpclientjsou 2017-05-19 20:12 1634 (0) 2 X pom.xml dependency > groupId > net.sourceforge.htmlunit groupId > artifactId > htmlunit artifactId > version > 2.26 version > dependency > dependency > groupId > org.jsoup groupId > artifactId > jsoup artifactId > version > 1.7.2 version > dependency > HtmlUnit(httpclient)jsoup API package com .yuanhai .test ; import java .io .IOException ; import java .net .MalformedURLException ; import org .jsoup .Connection ; import org .jsoup .Jsoup ; import org .jsoup .nodes .Document ; import org .jsoup .nodes .Element ; import org .jsoup .safety .Whitelist ; import org .jsoup .select .Elements ; import org .junit .Assert ; import org .junit .Test ; import com .gargoylesoftware .htmlunit .BrowserVersion ; import com .gargoylesoftware .htmlunit .DefaultCredentialsProvider ; import com .gargoylesoftware .htmlunit .NicelyResynchronizingAjaxController ; import com .gargoylesoftware .htmlunit .WebClient ; import com .gargoylesoftware .htmlunit .html .HtmlAnchor ; import com .gargoylesoftware .htmlunit .html .HtmlButton ; import com .gargoylesoftware .htmlunit .html .HtmlDivision ; import com .gargoylesoftware .htmlunit .html .HtmlForm ; import com .gargoylesoftware .htmlunit .html .HtmlInput ; import com .gargoylesoftware .htmlunit .html .HtmlPage ; import com .gargoylesoftware .htmlunit .html .HtmlSubmitInput ; import com .gargoylesoftware .htmlunit .html .HtmlTextInput ; // // 1. // js webClient .getOptions () .setJavaScriptEnabled (true) ; // JStrue webClient .getOptions () .setCssEnabled (false) ; // css // AjaxAjax webClient .setAjaxController (new NicelyResynchronizingAjaxController()) ; // Http error webClient .getOptions () .setThrowExceptionOnFailingStatusCode (false) ; // js webClient .getOptions () .setThrowExceptionOnScriptError (false) ; // js // HtmlPage page = webClient .getPage ( " ) ; // HtmlInput username = (HtmlInput) page .getElementById ( "userName" ) ; username .type ( "yourAccount" ) ; HtmlInput password = (HtmlInput) page .getElementById ( "password" ) ; password .type ( "yourPassword" ) ; // HtmlButton submit = (HtmlButton) page .getElementById ( "loginBtn" ) ; HtmlPage nextPage = submit .click () ; System .out .println (nextPage .asXml ()) ; } catch (Exception e) { e .printStackTrace () ; } } // jsoup Test public void jsoupParse() { try { /** HtmlUnitweb */ // chormeBrowserVersion. WebClient wc = new WebClient(BrowserVersion .CHROME ) ; wc .getOptions () .setJavaScriptEnabled (true) ; // JStrue wc .getOptions () .setCssEnabled (false) ; // css wc .getOptions () .setThrowExceptionOnScriptError (false) ; // js wc .getOptions () .setTimeout ( 10000 ) ; // 10S0 HtmlPage page = wc .getPage ( " ) ; String pageXml = page .asXml () ; // xml // text,htmlscript String pageText = page .asText () ; System .out .println (pageText) ; // get HtmlButton submit = (HtmlButton) page .getElementById ( "loginBtn" ) ; // XPathXPathId HtmlDivision div = (HtmlDivision) page .getByXPath ( "//div" ) .get ( 0 ) ; // java .util .List achList = page .getAnchors () ; for (HtmlAnchor ach : achList) { System .out .println (ach .getHrefAttribute ()) ; } System .out .println ( "-------jsoup------" ) ; // HTML, Jsoup .clean (pageXml, Whitelist .basic ()) ; /** jsoup */ // Stringdocument Document doc = Jsoup .parse (pageXml) ; Element loginBtn = doc .select ( "#loginBtn" ) .get ( 0 ) ; System .out .println (loginBtn .text ()) ; Assert .assertTrue (loginBtn .text () .contains ( "" )) ; } catch (Exception e) { e .printStackTrace () ; } } // htmlunit Test public void proxy() { String proxyHost = "192.168.0.1" ; int port = 80 ; WebClient webClient = new WebClient(BrowserVersion .CHROME , proxyHost, port) ; webClient .setAjaxController (new NicelyResynchronizingAjaxController()) ; DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient .getCredentialsProvider () ; String username = "account" ; String password = "password" ; credentialsProvider .addCredentials (username, password) ; } // jsoup Test public void jsoupCrawl() throws IOException { String url = " ; Connection con = Jsoup .connect (url) ;// // MIME con .header ( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" ) ; con .header ( "Accept-Encoding" , "gzip, deflate" ) ; con .header ( "Accept-Language" , "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3" ) ; con .header ( "Connection" , "keep-alive" ) ; con .header ( "Host" , url) ; con .header ( "User-Agent" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0" ) ; Document doc = con .get () ; Elements loginBtn = doc .select ( "#loginBtn" ) ; System .out .println (loginBtn .text ()) ;// js } } httpclientpost package com .yuanhai .test ; import java .io .IOException ; import java .security .cert .CertificateException ; import java .security .cert .X 509Certificate ; import java .util .ArrayList ; import java .util .List ; import javax .net .ssl .SSLContext ; import org .apache .http .Consts ; import org .apache .http .Header ; import org .apache .http .HttpResponse ; import org .apache .http .NameValuePair ; import org .apache .http .client .HttpClient ; import org .apache .http .client .entity .UrlEncodedFormEntity ; import org .apache .http .client .methods .HttpPost ; import org .apache .http .conn .ssl .SSLConnectionSocketFactory ; import org .apache .http .conn .ssl .SSLContextBuilder ; import org .apache .http .conn .ssl .TrustStrategy ; import org .apache .http .impl .client .HttpClients ; import org .apache .http .message .BasicNameValuePair ; import org .apache .http .util .EntityUtils ; import com .steadystate .css .parser .ParseException ; /** * author * date * version * */ public class TianyaTestByHttpClient { /** * jsHtmlUnit */ public static void main(String[] args) throws Exception { // // https HttpClient client = getSSLInsecureClient() ; // post HttpPost post = getPost() ; // , HttpResponse hr = client .execute (post) ; // showResponseInfo(hr) ; } private static void showResponseInfo(HttpResponse hr) throws ParseException, IOException { System .out .println ( "" + hr .getStatusLine ()) ; System .out .println ( "---------------------------------------------------------------" ) ; System .out .println ( "" ) ; Header[] allHeaders = hr .getAllHeaders () ; for (int i = 0 ; i System .out .println (allHeaders[i] .getName () + ":" + allHeaders[i] .getValue ()) ; } System .out .println ( "---------------------------------------------------------------" ) ; System .out .println ( "" ) ; System .out .println (EntityUtils .toString (hr .getEntity ())) ; /* location.href=" */ } // httpsHttpClientHttps // private static HttpClient getSSLInsecureClient() throws Exception { // SSLContext sslContext = new SSLContextBuilder() .loadTrustMaterial (null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true ; } }) .build () ; SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext) ; return HttpClients .custom ().// setSSLSocketFactory(sslsf)// // .setProxy (new HttpHost( "127.0.0.1" , 8888 )) .build () ; } // Post private static HttpPost getPost() { HttpPost post = new HttpPost( " ) ; // post .addHeader ( "Referer" , " ) ; post .addHeader ( "Host" , "passport.tianya.cn" ) ; post .addHeader ( "Origin" , " ) ; // // Listpost .setEntity // List paramsList = new ArrayList () ; /* * * firebug,httpWatch, * */ paramsList .add (new BasicNameValuePair( "Submit" , "" )) ; paramsList .add (new BasicNameValuePair( "fowardURL" , " )) ; paramsList .add (new BasicNameValuePair( "from" , "" )) ; paramsList .add (new BasicNameValuePair( "method" , "name" )) ; paramsList .add (new BasicNameValuePair( "returnURL" , "" )) ; paramsList .add (new BasicNameValuePair( "rmflag" , "1" )) ; paramsList .add (new BasicNameValuePair( "sid" , "1#1#1.0#a6c606d9-1efa-4e12-8ad5-3eefd12b8254" )) ; // paramsList .add (new BasicNameValuePair( "vwriter" , "yourAccount" )) ;// paramsList .add (new BasicNameValuePair( "vpassword" , "yourPassword" )) ;// // listpost post .setEntity (new UrlEncodedFormEntity(paramsList, Consts .UTF 8)) ; return post ; } } 0 0 Ubuntu Redis Jedis Jeesite HtmlUnithttpclientjsoup MySQL-- Htmlunit 58-- HtmlUnithttpclientjsoup SDCC 2017 Jsoup htmlunit SDCC 2017 jsoup -- java-jsouphtml -- htmlunitExcel Jsoup jsoup jsoup- * CSDN Quora Stackoverflow Github Facebook LEoe 103661 1564 1564 65 9 0 18 JavaWeb 14 423926 java web(22) c(5) Python(5) (3) java(9) redis(2) (3) linux(6) (7) docker(7) (2) (4) (1) 201801(2)201712(15)201711(6)201710(3)201709(7)201707(4)201706(2)201705(10)201704(5)201703(9)201702(2)201611(2)201610(1)201607(1)201606(1)201604(1)201603(3) PythonAnaconda(22651) MaveneclipseMaven(12172) tomcatweb(7023) Python(3949) (3875) DockerTomcat(3606) Webmagic cookie(3526) Jeesite(3506) Springmvc controllerjsp(2740) PythonFlask-Mail(2260) . Stack Overflow works best with JavaScript enabled .. You might have trouble submitting the form, but I'm sure it's possible via HttpUnit. Can you please check out my question Cannot login programmatically to facebook using htmlunit ? –Peter Dec 2 '15 at 16:56 add a comment Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Email Sign Up or sign in with Google Facebook Using HTMLUnit to log into Facebook programmatically using Java Ask Question up vote 3 down vote favorite 2 This question is kinda an addition to this question: How to log into Facebook programmatically using Java? I have used (a slightly modified version of) the following code to log into accounts of other websites just fine 5a02188284
http://www.pearltrees.com/imdisnirach/item217200825 http://profexonproph.diarynote.jp/201801100110053598/ http://supreme-team.xooit.fr/viewtopic.php?p=331 https://www.flickr.com/groups/4376524@N25/discuss/72157689221569612/ https://granwicotea.wixsite.com/afkafibju/single-post/2018/01/09/Facebook-Auto-Like-Iphone https://eldivithenupmogety.wixsite.com/vilopec/single-post/2018/01/09/Get-Facebook-Application-Id http://brusummeryfor.hatenablog.jp/entry/2018/01/10/011020 http://revokewith.lnwshop.com/article/59/como-usar-o-free-facebook-downloader-no-celular https://disqus.com/home/discussion/channel-dakemej/facebook_for_windows_phone_75_chat/ http://reharhindnond.diarynote.jp/201801100109501508/
Annons