Search code examples
javascripthtmlwebiframe

Loading a specific div from another website into own website


Ive tried using the js load function but as the external site does not allow CORS requests, my original GET request gets blocked.

<div id="test"></div>
<script>
    $(document).ready(function () {
        $("#test").load("https://mywebsite.com");
    });
</script>

So it seems that my only approach is to use iframes?! Is there a way to only crawl a specific div with iframes? I dont want to display the whole website.

EDIT: Since I am using Django I was able to crawl the website with python in a view and then push the crawled and cleaned up code snippet in the html template. Nevertheless to answer my question -> There is no correct way of doing it as long as the website you are trying to access is blocking the content.


Solution

  • Work with the owner of the site you want to take content from.

    They can set you up with an API. That avoids having to use hackey methods or risking copyright-related legal trouble.