Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static byte[] compress(String string) throws IOException {
- ByteArrayOutputStream os = new ByteArrayOutputStream(string.length());
- GZIPOutputStream gos = new GZIPOutputStream(os);
- gos.write(string.getBytes());
- gos.close();
- byte[] compressed = os.toByteArray();
- os.close();
- return compressed;
- }
- public void postData(String html) {
- URL url = null;
- BufferedReader reader = null;
- StringBuilder stringBuilder;
- try {
- url = new URL("http://192.168.0.15/android.php");
- // html = compress(html);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setReadTimeout(10000);
- conn.setConnectTimeout(15000);
- conn.setRequestMethod("POST");
- conn.setDoInput(true);
- conn.setDoOutput(true);
- Uri.Builder builder = new Uri.Builder()
- .appendQueryParameter("par", html);
- String query = builder.build().getEncodedQuery();
- OutputStream os = conn.getOutputStream();
- BufferedWriter writer = new BufferedWriter(
- new OutputStreamWriter(os, "UTF-8"));
- writer.write(query);
- writer.flush();
- writer.close();
- os.close();
- conn.connect();
- reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- stringBuilder = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null)
- {
- stringBuilder.append(line + "\n");
- }
- String output = stringBuilder.toString();
- Log.d("httpcliente", "BUSCANDO => [" + output + "]");
- } catch (IOException e) {
- e.printStackTrace();
- }
- //===========
- private class ParseURL extends AsyncTask<String, Void, String> {
- @Override
- protected String doInBackground(String... strings) {
- StringBuffer buffer = new StringBuffer();
- try {
- Log.d("JSwa", "Connecting to ["+strings[0]+"]");
- Document doc = Jsoup.connect(strings[0]).get();
- Log.d("JSwa", "Connected to ["+strings[0]+"]");
- // Get document (HTML page) title
- String title = doc.title();
- Log.d("JSwA", "Title ["+title+"]");
- buffer.append("Title: " + title + "\r\n");
- // Get meta info
- Elements metaElems = doc.select("meta");
- buffer.append("META DATA\r\n");
- for (Element metaElem : metaElems) {
- String name = metaElem.attr("name");
- String content = metaElem.attr("content");
- buffer.append("name ["+name+"] - content ["+content+"] \r\n");
- }
- Elements topicList = doc.select("h2.topic");
- buffer.append("Topic list\r\n");
- for (Element topic : topicList) {
- String data = topic.text();
- buffer.append("Data [" + data + "] \r\n");
- }
- postData(doc.html());
- Elements scriptElements = doc.getElementsByTag("script");
- // Elements scriptElements = doc.getElementsByTag("script");
- buffer.append("Variavel resultado1\r\n");
- for (Element element :scriptElements ){
- for (DataNode node : element.dataNodes()) {
- //System.out.println(node.getWholeData());
- String scriptdata = node.getWholeData();
- String scriptdata2 = node.toString();
- //buffer.append("StriptData [" + scriptdata + "] \r\n");
- //String resultado1
- String procurarPor = "codigoinicial";
- if(scriptdata2.toLowerCase().contains(procurarPor.toLowerCase())){
- // buffer.append("StriptData=1 [" + scriptdata2 + "] \r\n");
- // System.out.println("StriptData=1 [" + scriptdata2 + "] \r\n");
- String text =
- "This is the text to be searched " +
- "for occurrences of the http:// pattern.";
- text = scriptdata2;
- String patternString = ".*http";
- Pattern pattern = Pattern.compile(patternString);
- Matcher m = pattern.matcher(text);
- }
- }
- System.out.println("-------------------");
- }
- }
- catch(Throwable t) {
- t.printStackTrace();
- }
- return buffer.toString();
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- respText.setText(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement