java - Attemping to manipulate data entry for a web page using jsoup -


i attempting enter data web site. post important snippet of web site here, target web page can found here

the values street address number , street name represented inpnumber , inpstreet.

html:

<td width="48">    <input type="text" id="inpnumber" name="inpnumber" class="input" size="5" value="" onkeypress="clearaction(this)" />  </td>    <td width="40">    <input type="text" id="inpunit" name="inpunit" class="input" size="4" value="" onkeypress="clearaction(this)" />  </td>    <td width="160">    <input type="text" id="inpstreet" name="inpstreet" class="input" size="20" value="" onkeypress="clearaction(this)" />  </td>

only inpstreet , inpnumber needed effective query , need enter these values.

what have tried far:

string url = "http://icare.fairfaxcounty.gov/ffxcare/search/commonsearch.aspx?mode=address";     try {     connection.response response = jsoup.connect(url)                 .useragent("mozilla/5.0")                 .timeout(10 * 10000)                 .method(connection.method.post)                 .data("inpnumber", "4127")                 .data("inpunit", "")                 .data("inpstreet", "winter harbor")                 .data("btsearch", "")                 .data("inpsuffix1", "")                 .followredirects(true)                 .execute();      //parse document response     document document = response.parse();     system.out.println(" extracting information site ");      filewriter fw = new filewriter("doc.html");     bufferedwriter bw = new bufferedwriter(fw);     bw.write(document.html());     bw.close(); } catch (exception ex){     ex.printstacktrace(); } 

i have tried several variations on above code, including more/less key/pair values (setting , returning "" values found looking @ firebug), looking @ return values , general changes jsoup.connect(url) call.

the result in doc.html file original unaltered page. doing wrong?

the information being sent payload , best way use send information using requestbody(string). code below tested working.

imports:

import java.io.bufferedwriter; import java.io.filewriter;  import org.jsoup.*; import org.jsoup.nodes.document; import org.jsoup.select.elements;  import static java.net.urlencoder.encode; 

code:

public static void main(string[] args) {     string url = "http://icare.fairfaxcounty.gov/ffxcare/search/commonsearch.aspx?mode=address";     string useragent = "mozilla/5.0 (windows nt 6.1; win64; x64; rv:55.0) gecko/20100101 firefox/55.0";      try {          // required information validation         // note might want make method out of , call whenever need instead of         elements inputs = jsoup.connect(url)                 .useragent(useragent)                 .get().select("input");          string eventvalidation = encode(inputs.select("#__eventvalidation").attr("value"), "utf-8");         string viewstategen = encode(inputs.select("#__viewstategenerator").attr("value"), "utf-8");         string viewstate = encode(inputs.select("#__viewstate").attr("value"), "utf-8");           int number = 4127;         string street = encode("winter harbor", "utf-8");          // not necessary         string unit = "";         string suffix = "";          document document = jsoup.connect(url)                 .useragent(useragent)                 .requestbody(                         string.format(                                 "mode=address"                                 + "&__viewstate=%s"                                 + "&__viewstategenerator=%s"                                 + "&__eventvalidation=%s"                                 + "&inpnumber=%d"                                 + "&inpunit=%s"                                 + "&inpstreet=%s"                                 + "&inpsuffix1=%s",                                  viewstate, viewstategen, eventvalidation,                                 number, unit, street, suffix))                 .post();           system.out.println("extracting information site...");          filewriter fw = new filewriter("doc.html");         bufferedwriter bw = new bufferedwriter(fw);         bw.write(document.html());         bw.close();          system.out.println("done.");     } catch (exception ex) {         //todo handle exceptions         ex.printstacktrace();     }  } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -