Call a url and remove specific html-elements

Hi, I’m new to Scriptable and to JS in general. I’m trying to call a url and remove specific div-elements by id or class name.

Suppose I want to remove the logo (class=“logo”) from https://scriptable.app. What I have so far is the following:

url = "https://scriptable.app"
let req = new Request(url)
let html = await req.loadString()

WebView.loadHTML(html)

I have currently two questions:

  1. How can I use a method like getElementById() on my html (to then remove it)?
  2. When (web)viewing the html in the end, all the links are not active anymore. Is there a better way to do it?
1 Like

You are on the right path.

Now you need an instance of WebView and then call evaluateJavaScript() on the instance. Pass it your script to remove items as string (there you can use getElementById()). After that, call getHTML() to retrieve the HTML.

On a side note you can also directly load the URL with the WebView, you don’t need to do it manually with Request

1 Like