0

I was wondering if I could get some data from another website to get it displayed on mine. The good example can be alexa.com. I need to display Alexa traffic rank and reputation in a div for example on my page, so it will be changed dynamically each time Alexa change its data.

Thank you for your help.

Art
  • 279
  • 2
  • 7
  • 20

2 Answers2

0

One way is to make an ajax request for the Alexa.com site, once you receive all the html, then you can use jquery or something to scrape it for the div you want. It feels kinda dirty, but its an easy way to get what you want. Though this is assuming their page content isn't loaded dynamically.

Edit: See this for more info: Request external website data using jQuery ajax

Community
  • 1
  • 1
Amy
  • 7,388
  • 2
  • 20
  • 31
  • so I can't just say to go to the particular id or class on the alexa page and get data that is displayed in there? Can you please write an example? – Art Mar 08 '13 at 05:36
  • You can use regex and find what you want. Or the slow way is to create the DOM using the scraped markup and then use jquery to select what you want. (This method would be slower than regex, I think) – Amy Mar 08 '13 at 05:39
  • 1
    Maybe there is another language like PHP or something is better for this task? – Art Mar 08 '13 at 05:55
0

yahoo yql... (instead of a php? proxy serverside script)..

I have a sneaky suspicion you do not own/control the external link site, so getting content from a different site, would fall under cross-domain security restrictions (to a modern browser).

So in order to regain 'power to the user', just use http://query.yahooapis.com/.
jQuery would not be strictly needed.

EXAMPLE 1:
Using the SQL-like command:

select * from html 
where url="http://stackoverflow.com" 
and xpath='//div/h3/a'

The following link will scrape SO for the newest questions (bypassing cross-domain security bull$#!7):
http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20html%20where%20url%3D%22http%3A%2F%2Fstackoverflow.com%22%20and%0A%20%20%20%20%20%20xpath%3D%27%2F%2Fdiv%2Fh3%2Fa%27%0A%20%20%20%20&format=json&callback=cbfunc

As you can see this will return a JSON array (one can also choose xml) and calling the callback-function: cbfunc.

Indeed, as a 'bonus' you also save a kitten every time you did not need to regex data out of 'tag-soup'.

Do you hear your little mad scientist inside yourself starting to giggle?

Then see this answer for more info (and don't forget it's comments for more examples).

Good Luck!

Community
  • 1
  • 1
GitaarLAB
  • 14,536
  • 11
  • 60
  • 80