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.

2
  • Cant you use iframes? Commented Mar 8, 2013 at 5:31
  • no, I only need data, numbers in this case. Commented Mar 8, 2013 at 5:33

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

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?
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)
Maybe there is another language like PHP or something is better for this task?
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!

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.