0

I need to get an element with a div id from an external web page.

This is the code I tried to work with but it doesn't return anything.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>TEST</title>
    <style>
      body {
        font-size: 12px;
        font-family: Arial;
      }
    </style>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  </head>
  <body>

  <b>Output:</b>
  <ol id="tablepress-34_wrapper"></ol>

  <script>
    $( "#tablepress-34_wrapper" ).load( "https://mrafiee.net/daily-bonus-digital-communication/" );
  </script>

  </body>
</html>

For example, I want to get the table showing in that page in another external page. How can I do it ? Thanks

rrk
  • 15,677
  • 4
  • 29
  • 45
Majid
  • 421
  • 6
  • 19
  • use a proper scraping library to do this – Kunal Mukherjee May 06 '19 at 13:04
  • 1
    It doesn't return anything because of cross-domain restrictions. You'll have to use a different method to grab data from an external domain. See: https://stackoverflow.com/questions/14999573/jquery-load-external-site-page – Liftoff May 06 '19 at 13:06
  • *"it doesn't return anything"* - are you sure it doesn't return an error? You're not checking for one – freedomn-m May 06 '19 at 13:08
  • [Use BeautifulSoup4 library](https://www.crummy.com/software/BeautifulSoup/bs4/doc/). I've used it previously and it plays quite well – jeffXradon May 06 '19 at 13:08

1 Answers1

-1

The issue you are facing is due to the CORS policy. A workaround would be to use a proxy service such as https://cors-anywhere.herokuapp.com/; For instance the following injects the first div of the remote site into the body

$('body').load('https://cors-anywhere.herokuapp.com/https://mrafiee.net/daily-bonus-digital-communication/ div')
Ashen Gunaratne
  • 435
  • 3
  • 9