There is a site on the main page of which there is a search form.

<div class="formText"><input id="search_input" class="text ui-autocomplete-input" name="kp_query" autocomplete="off" maxlength="256" value="" tabindex="1" type="text"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span></div> <input class="searchButton1" value="" tabindex="2" onclick="if(!!document.getElementById('search_input').value &amp;&amp; document.getElementById('search_input').value != 'поиск') {document.searchForm.first.value = 'no'; document.searchForm.submit();}" type="button"> 

The result of the search is a site page that will be parsed using Java tools. Actually the question is how to make a search request in Java and get the address of the page found? If possible, at least a few lines of code.

  • There are several http clients for java. Even it seems there is a built-in, but I do not know for sure, I have not used it. And used apache http client. With the help of the client, you make requests, get answers. Depending on the response format, the appropriate parser is used. For xml or json, the parser is usually always at hand. A good parser html must also search. - Sergey
  • To @Sergey. The question is not about parsers, the parser itself has already been written and is working, the question is how to request the address of the page to be parsed. - Tariel
  • In the first lines of my previous letter it seems to have mentioned http clients. Googling is very simple. See what is immediately "in the box" java - HttpURLConnection ? Do not like it - I recommend the apache http client , If this one does not like it - look no further, I have not contacted others. Do not write the same for you request. - Sergey
  • A simple way to make a query with the "bourgeois" SO: stackoverflow.com/questions/1485708/… - ygun
  • The answer never received. I know how to use the HTTP client, if the resulting page of the site is known, then the parser works. The question is completely different, I need to get the address of this page which is returned when using the search form, the code of which I cited. Once again, my question is not how to use the Http client, but how to create a request for the above code, in which to transfer the required value and get the address of the page found. - Tariel

1 answer 1

Judging by the javascript in your example, somewhere in the source page there is a html form element, most likely with the identifier "searchForm" (for example: name = "searchForm"), in the attributes of which the address where the request is sent should be specified.

  • one
    You also need to specify the parameters of this form in the request. The search string is most likely <input id="search_input" class="text ui-autocomplete-input" name="kp_query" . So there should be a parameter kp_query = чего там ищите . document.searchForm.first.value = 'no' hints that there is a first parameter and it should most likely be set to no . Thus, view the form, identify the parameters and send POST (most likely, POST or GET is determined by one of the attributes of the form) request with these parameters filled with the necessary values. - Sergey
  • And you can ask for an example request? And then with scripting languages ​​I really bad. - Tariel
  • Easier, If you provide the source html code of the page, from the example - ygun
  • @Tariel What does the scripting language have to do with it? You wanted to get everything to java and search results, etc.? You need to find out from the code of the search page the parameters that are used in the form and the address to which to send the request (with these parameters) and from it you will receive your page for the parser. You yourself can not make out the search page - bring it in full, not two lines. - Sergey
  • @Sergey is all right, I’m stuck on exactly how to know the parameters and where to send. Nothing is clear from the form code. - Tariel