Skip to main content

Notifications

Community site session details
Power Automate - Power Automate Desktop
Answered

How to get all URLs on a web page?

Like (0) ShareShare
ReportReport
Posted on 18 Jan 2023 21:19:39 by 6

Hi all - I would like to get all the URLs available on a web page similar to the Chrome console function that prints all the URLs in the console. 

 

 

var urls = document.getElementsByTagName('a');

for (url in urls) {
 console.log ( urls[url].href );}

 

 

Is the 'Run JavaScript Function on Web Page' the right function to use? If yes, how can I modify the code above to render the URLs? I have tried the following, but it only returns [object Object] as the result. 

 

 

var urls = document.getElementsByTagName('a');
var urlList = [];
for (var i = 0; i < urls.length; i++) {
 urlList.push(urls[i].href);}
return urlList;
}

 

 

Any pointers would be very much appreciated! ThanksCapture.PNG

  • VJR Profile Picture
    7,635 on 20 Jan 2023 at 04:28:45
    Re: How to get all URLs on a web page?

    This will definitely need you to know all links on that website.

    Some sites do have a sitemap, so you can try accessing that.

     

    Another thing you can look at is:

    - Launch <browser>

    - Get details of web page (this will give a variable)

    - Use that variable in "Recognise entities in Text" (select URL in dropdown)

     

    Then again go into each of the links generated using above steps and then again more links from those links.

    But of course this is going to extract every single thing that looks like an URL eg; image links, etc.

     

    You can do some research and see where/how it goes.

  • fskdnl Profile Picture
    6 on 19 Jan 2023 at 09:38:04
    Re: How to get all URLs on a web page?

    Thanks so much for the solution! Much appreciated.

     

    As a follow-up question, instead of getting all URLs on a web page, I would like to get all the URLs on a website when given a domain name. Can this be achieved via Power Automate Desktop as well? Thanks!

  • Verified answer
    VJR Profile Picture
    7,635 on 19 Jan 2023 at 04:44:32
    Re: How to get all URLs on a web page?

     

    Add this in the javascript on webpage action.

     

    function ExecuteScript() 
    
    { 
    
    var links = document.getElementsByTagName('a');
    var list = "";
    for(var i = 0; i< links.length; i++)
    {
     list = list + links[i].href + "\n";
    }
    
    return(list);
    }

     

    Output in a Text variable:

    VJR_0-1674103009222.png

     

    Split it by newline using Split Text if you want the result in a List variable so that you can iterate through it.

     

    VJR_2-1674103427323.png

     

     

     

    List variable:

    VJR_1-1674103356962.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 27 Super User 2025 Season 1

#2
Nived_Nambiar Profile Picture

Nived_Nambiar 18 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 7 Super User 2025 Season 1

Overall leaderboard
Loading started
Loading started