Get list from webview javascript evaluate

How to get the list of links, quality, format and size
from this site using evaluate javascript and store in variable and show in listview in my app ?
I want to get lists
1: “download video” table data
2: " Download Sound Only" table data in two different list variables
Website:

can anyone help me ?
i want to make video downloader using this site . i know someone says that you can use api to make video downloader but i just want to learn something new please help me

Hello Muhammad_zain!
Come on, I’ll try to help you!!
First we are going to put the link of the website that you want to use to create the download options.
Let’s set the webview url to https://youtube4kdownloader.com/.

Second, we are going to create an event to add the link of the video you want to download using the EvaluateJavasCript block and define the text with the command

document.getElementById("video").value = "here you will put the download link";

Third, you will also create the command in EvaluateJavaScript to click download.

document.querySelector("body > div.main-wrapper > div.main-content > main > section.banner-area.search-area > div > div.formContainer > form > input.downloadBtn").click();.

Okay, now you can get the list of files to download.

Fourth part, get the files to download - For this we will continue using evaluateJavaScript only now with the following code:

function parseHtmlTable(html) {
  const parser = new DOMParser();
  const document = parser.parseFromString(html, "text/html");
  let list = [];
  const table = document.querySelector("body > div.main-wrapper > div.main-content > main > section.download-area > div > div.col-md-8 > table:nth-child(3)");
  const rows = table.querySelectorAll("tr");
  for (let i = 0; i < rows.length; i++) {
    const qualityCell = rows[i].querySelector("td[title]");
    const formatCell = rows[i].querySelector("td:nth-child(2)");
    const sizeCell = rows[i].querySelector("td span");
    const linkCell = rows[i].querySelector("td a");
    if (qualityCell && formatCell && sizeCell && linkCell) {
      const quality = qualityCell.textContent;
      const format = formatCell.textContent;
      const size = sizeCell.textContent;
      const link = linkCell.getAttribute("href");
      let sublist = [];
      sublist.push(quality);
      sublist.push(format);
      sublist.push(size);
      sublist.push(link);
      list.push(sublist);
    }
  }
  return list;
}
const html = document.documentElement.outerHTML;
const result = parseHtmlTable(html);
parseHtmlTable(html);

using the Webview Return Block called AfterEvaluationJavaScript you will get a list of all the videos on the website.


Oh, don’t forget to add the web component to transform the return with the JsonTextDecode block.

You can use the same logic to get the video without audio and then the mp3 file.

I would like to take the opportunity to thank my friend Aryan Gupta who already helped me a lot with appzard.

2 Likes

I am really thankful to you for help me.
But in this method you used evaluate javascript block 3 times and when we evaluate js 1st time than also run the “after js evaluated” block so we will got error for 1st and 2nd time. And than 3rd time we will get our list.

So is there any way to combine all tge coding in one block ?
And run the 3rd code automatically when website generat all download list. Because if we use clock timer than sometimes user’s Internet connect slow than we got error

Hi Muhammad_zain,
I didn’t understand exactly the errors you referred to, but I made the logic of what you need, check it out to see if that’s what you were wanting.
I make some changes.
the code to scrap list now is

function printTableData() {
  var table = document.querySelector("body > div.main-wrapper > div.main-content > main > section.download-area > div > div.col-md-8 > table:nth-child(3)");
  var rows = table.rows;
  var headers = rows[0].cells;

  var result = [];
  for (var i = 1; i < rows.length; i++) {
    var obj = {};
    var cells = rows[i].cells;
    for (var j = 0; j < cells.length; j++) {
      var headerText = headers[j].innerText;
      var cellText = cells[j].innerText;
      if (headerText === "Download") {
        var link = cells[j].querySelector("a").href;
        obj[headerText] = link;
      } else {
        obj[headerText] = cellText;
      }
    }
    result.push(obj);
  }

  return result;
}

printTableData();

the previous one was not working properly.

This is the image of all the blocks I used.

There is the .aia
VideoDownloader.aia (3.5 KB)

@AryanGupta I noticed something that didn’t happen before, if I set the webview visible to false, the code stops working as if the page wasn’t loading, but I’ve used the webview that way other times and it worked even though it was invisible.

1 Like

Hi @Drumblow_FabricApps
Your code helps me a lot thanks for your help.
1st please tell me how can i learn this kind of JavaScript ? Because i want to learn.
And second i am facing a issue that when my webview invisible than the code isn’t run

function printTableData() {
  var table = document.querySelector("body > div.main-wrapper > div.main-content > main > section.download-area > div > div.col-md-8 > table:nth-child(3)");
  var rows = table.rows;
  var headers = rows[0].cells;

  var result = [];
  for (var i = 1; i < rows.length; i++) {
    var obj = {};
    var cells = rows[i].cells;
    for (var j = 0; j < cells.length; j++) {
      var headerText = headers[j].innerText;
      var cellText = cells[j].innerText;
      if (headerText === "Download") {
        var link = cells[j].querySelector("a").href;
        obj[headerText] = link;
      } else {
        obj[headerText] = cellText;
      }
    }
    result.push(obj);
  }

  return result;
}

printTableData();

Let’s test this now to see if it works! ahahaha

I’m glad I could help.
About learning to program, you can take an online course or tutorials on the internet, I’m still learning too and that’s why I made so many mistakes in the codes above. Now we also have help from gpt chat, you can use it to help you learn.
About the invisible webview I can’t help, it’s the first time I’ve seen this happen, I don’t know if it’s something from the appzard or the website we’re getting the information from. We need the help of some developer to explain this to us.

2 Likes

Can you tell me the website name from where you learned ?