2

I got a website where I do movie reviews. The website is made using datalife engine and as little as I know about DLE, there are no way to use plug-ins.

I'm trying to build simple code that gets the text inside a DIV on the IMDB website, and prints out on mine. What i am looking for is a way to give the IMDB link of the movie when i'm reviewing the movie, and the scripts get's the element with the class name "titlePageSprite star-box-giga-star" and print it out on my website.

I've been searching for this, and as far as i know, the best way is to use jquery (which i know nothing about btw) and when i implement the code i think it's right, it simply doesn't print nothing out...

What i teste out was this Put this between the tag

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

(i think i've tried with a link from jquery 1.9 if you are asking)

Then put this on the body for testing:

<script type="text/javascript">
jQuery(function($){
    $('#result').load('http://www.imdb.com/title/tt2306299/ #titlePageSprite star-box-giga-star');
});
</script>

And tested printing out with this where i wanted to print

<div id="result"></div>

Nothing happend at all.

3
  • 1
    No, you cant. you need to scrap the whole page and parse it to get the part of the page you need.in other words...download the entire page content into a string (using AJAX). and then use java Script functions such as split, substring etc to get the content which you need. its NOT the best practice but might do the trick if everything else fails. Apr 1, 2013 at 2:34
  • One of the comments you can find that IMDB is not allowing scarping. I don't have evidence for that statement but, if this is the case then just have a declaration that the some data provided may not match the actual data.
    – NewUser
    Apr 1, 2013 at 3:16
  • You can use Curl to scrape the website
    – Youss
    Apr 2, 2013 at 12:13

1 Answer 1

1

Your example shows what is called a cross-origin request (CORS), and unless the target website (imdb) has allowed this, you will see errors in the browser console instead of the expected result.

2
  • but the code itself is right? So is the best way just to make this manually?
    – Pedro Lino
    Apr 1, 2013 at 2:12
  • There are multiple ways to overcome the same origin policy of browsers, most involve proxies or scripts that you control. There are several good questions with great answers here on SE under the "CORS" tag. Apr 1, 2013 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.