Write a browser bookmarklet in order to extract nested xml sitemaps links
- User
Write a browser bookmarklet in order to extract nested xml sitemaps links
- Assistant
Creating a browser bookmarklet to extract nested XML sitemap links would require a little bit of JavaScript knowledge. Here is a simple example of how you can achieve it:
javascript:(function() { fetch(document.URL) .then(response => response.text()) .then(data => { const parser = new DOMParser(); const xml = parser.parseFromString(data, "text/xml"); const sitemaps = xml.getElementsByTagName("sitemap"); const urls = Array.from(sitemaps).map(sitemap => sitemap.getElementsByTagName("loc")[0].textContent); console.log(urls); }); })();Here is the breakdown of the steps:
- Fetch the current page's content.
- Parse the fetched content as XML.
- Find all elements named "sitemap".
- For each "sitemap" element found, get the text content of its "loc" child.
- Log the array of URLs to the console.
To use this as a bookmarklet, create a new bookmark in your browser, set the URL to the JavaScript code, and click it when you're on a page with nested XML sitemaps. The console will display all found URLs.
Remember, this is a very simple script and might need adjustments depending on the structure of the XML sitemap on the site you're using it on. Also, this script doesn't handle errors or edge cases.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.