![]() Set AppleScript's text item delimiters to oldTIDS ORANGE - Actions that permanently destroy Varibles or Clipboards YELLOW - Primary Actions (usually the main purpose of the macro) MAGENTA - Actions designed to be customized by user GREEN - Key Comments designed to highlight main sections of macro To facilitate the reading, customizing, and maintenance of this macro, This macro uses Google Chrome, but can be easily changed.Any Action in magenta color is designed to be changed by end-user.Using RegEx, parses it into Title and URL.Returns a TAB delimited String, with each link on a separate line.Builds a TAB delimited list (array) of Link Text & URL from that collection.Gets a HTML Collection of all Links (Anchor Tags) within that collection.Gets a HTML Collection of all Elements that have the specified Class Name.If your web page has a lot of links, it is best to first TEST on a similar page with just a few links).ADD Actions at the bottom of the Macro to process each link as you desire.Set the below Action "SET HTML Class" to the unique Class of the HTML Element that contains each, or all, of the list of links.Set the below Action "SET Source URL" to the URL of the Web Page that contains the list of links.(Note: This macro can be used ONLY with Google Chrome, but could be easily changed to use Safari, just by replacing the Chrome Actions with Safari Actions).Move Macro to Macro Group that limits trigger to apps you plan to use it with.In some cases, they MUST be changed to fit your specific requirements. Note that all Actions with the magenta color are designed to be changed by you. Extract Web Page Links Using HTML Class, and Process Each Link Just post the URL of the target page.Īuthor. If it does not work for you, we can probably figure out a method that will. This method/macro won't work in all cases, but hopefully it will in most cases. You can easily find this HTML element, and its Class, by using the Inspector in either Chrome or Safari. Most often, these list of links will either be within a major HTML element with a unique Class, or each link will be within an element that has the same Class for all of these elements. None of which requires the user to understand or change JavaScript. Make it easy for most users, most use cases, to extract all hyperlinks in a list on a web page, and then process each link. It is provided as an example of how you can use submacros with this macro.īe sure to read the Macro Setup in the Release Notes section below. This macro uses (but does not require) this Process a Web Page Hyperlink (28.6 KB) VER: 1.1 Extract & Process Links on Web Page Using HTML Class. var links = document.querySelectorAll('a') įor (var i = links.MACRO: Extract & Process Links on Web Page Using HTML Class If you want to extract the external URLs only, then this is the code you need to use. var urls = document.querySelectorAll('a') Ĭonsole.log(urls.href) Extract External URLs OnlyĮxternal Links are the ones that point outside the current domain. If you are using Chrome or Firefox use the following code for a styled version of the same.ĭemo of extracting links from Wikipedia page using dev console var urls = document.querySelectorAll('a') Ĭonsole.log("%c#"+url+" > %c"+urls.innerHTML +" > %c"+urls.href,"color:red ","color:green ","color:blue ") Īnd if you want to extract just the links without the anchor text, then use the following code. } Extract URLs + Corresponding Anchor Text – Styled Output (For Chrome & Firefox) var urls = document.querySelectorAll('a') Ĭonsole.log("#"+url+" > "+urls.innerHTML +" > "+urls.href) ![]() ![]() The following is a cross-browser supported code for extracting URLs along with their anchor text. Copy the code, paste it into the console and hit enter. The JavaScript snippets to extract links are given below. I can’t stress enough how useful that is! To open the console on Chrome, press Cmd + Shift + i on Mac and Ctrl + Shift + i on Windows. You can write JavaScript code and inject it into the current page to do all sorts of fancy things. The browser console is an excellent tool to test and debug things. Two other techniques to extract links from page are also shared here for people who don’t want to get their hands dirty with code □. If you are impressed with this, do learn some JavaScript as it comes very handy. This article serves as a short demonstration of how you can use browser developer consoles to scrape data from the web page. What do you do when you want to export all or specific links from a webpage? Copying them one after another is monotonous and useless especially when you can automate it with a line of JavaScript code. Extracting URLs using Dev Tools console. ![]()
0 Comments
Leave a Reply. |