Skip to content
The Chat Archive
gpt-4-0613· OpenAIHugging Face Arena Human Preference 55K

Write a browser bookmarklet in order to extract nested xml sitemaps links

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-2.0’s answer.
  1. User

    Write a browser bookmarklet in order to extract nested xml sitemaps links

  2. 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:

    1. Fetch the current page's content.
    2. Parse the fetched content as XML.
    3. Find all elements named "sitemap".
    4. For each "sitemap" element found, get the text content of its "loc" child.
    5. 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.