How do I make an extension that retrieves the source code of a web page?

oh, that's right, it slipped my mind :no_mouth:, thank you very much.

1 Like

Hello, I know I'm a bit heavy, but I can't understand the errors. I have fixed the ";" and I get the following error:

Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml

extensions:

clean:

init:

common_CommonUtils:

init:

CommonUtils:

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

CopyToRunLibDir:

components_AndroidRuntime:

init:

CommonConstants:
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning

HtmlEntities:
[javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

AndroidRuntime:
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/meulencv/Get_source_web/Get_source_web.java:93: error: cannot find symbol
[javac] myEvent(finalData); // You're event with data
[javac] ^
[javac] symbol: method myEvent(String)
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/meulencv/Get_source_web/Get_source_web.java:90: error: cannot find symbol
[javac] activity.runOnUiThread(new Runnable() { // Always raise events on UI thread
[javac] ^
[javac] symbol: variable activity
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
[javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 7 seconds
cts/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/meulencv/Get_source_web/Get_source_web.java:93: error: cannot find symbol
[javac] myEvent(finalData); // You're event with data
[javac] ^
[javac] symbol: method myEvent(String)
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/meulencv/Get_source_web/Get_source_web.java:90: error: cannot find symbol
[javac] activity.runOnUiThread(new Runnable() { // Always raise events on UI thread
[javac] ^
[javac] symbol: variable activity
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
[javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 6 seconds

I don't find the resolution of the errors on the internet

Your code have two errors:

  1. you haven't declared and initialized activity
  2. there is no myEvent method in your code

You should use a Java IDE.

3 Likes

This can be done with AI2 Blocks, just join view-source: before the http part?

3 Likes

this can do the same thing too, so I think we don't need an extension for that @Meulencv

blocks (3)

3 Likes

Still, it's okay for learning :wink:

3 Likes

But I ned to do this, to later do the extension more complex, for example a extension that gives the bitcoin price.

Hello,
I would be very grateful if you could fix my code, thank you very much :slightly_smiling_face:

@Meulencv did you fixed that?

1 Like

I have the demo extension code which works.

Demo code

File name: Request.java

package com.kumaraswamy.request;

import android.app.Activity;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.util.AsynchUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

@DesignerComponent(version = 1,
        category = ComponentCategory.EXTENSION,
        description = "Made my YOU",
        nonVisible = true,
        iconName = "ICON LINK")

@SimpleObject(external = true)

public class Request extends AndroidNonvisibleComponent {

    private Activity activity;

    public Request(ComponentContainer container) {
        super(container.$form());
        activity = container.$context();
    }

    @SimpleFunction
    public void DoRequest(final String website) {
        AsynchUtil.runAsynchronously(new Runnable() {
            @Override
            public void run() {
                BufferedReader in;
                try {
                    in = new BufferedReader(
                            new InputStreamReader(
                                    new URL(website).openStream()));

                    String inputLine;
                    final StringBuilder result = new StringBuilder();

                    while ((inputLine = in.readLine()) != null)
                        result.append(inputLine);

                    in.close();

                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            GotResult(result.toString());
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @SimpleEvent
    public void GotResult(String result) {
        EventDispatcher.dispatchEvent(this, "GotResult", result);
    }
}
8 Likes

Thank you very much with all my heart @Kumaraswamy , I don't know how to thank you. IT WORKS! :grin: :grin: :grin:

1 Like

used your code and got compile error in kodular

    Kodular is unable to compile this project.
The compiler error output was
________Preparing application icon
________Creating animation xml
________Creating fragment xml
________Creating listview xml in res/layout/..
________Creating listview xml in res/layout-v21/..
________Creating xml in res/drawable/..
________Creating splash png in res/drawable/..
________Creating colors xml
________Creating styles xml
________Creating drawables xml v21
________Checking for firebase
________Creating provider_path xml
________Creating network_security_config xml
________Generating adaptive icon file
________Generating round adaptive icon file
________Generating adaptive icon background file
________Generating manifest file
________Attaching native libraries
________Attaching Android Archive (AAR) libraries
________Attaching component assets
________Invoking AAPT
AAPT time: 1.217 seconds
________Compiling source files
.
1 Like

I'm solving the problem

I have solved the problem, thank you very much for the warning. :grinning:

It's not the fault of the extension, I have compiled the code over two times...

1 Like

Extensions. I added this extension to an empty project and it hasn't compiled anymore.

1 Like

Hi, it compiles correctly for me and the app works on the mobile. Have you tried v2 of the extension?

1 Like

Can you tell us what changes did you make in the source code which @Kumaraswamy provided?

1 Like

It do like web scrapping,
When the extension get the source of the web page, it cut a part of the source to get the value like (btc price)