0

Possible Duplicate:
Can Javascript read the source of any web page?

How can i retrieve content from an external website, using javascript/jquery? I would like to get some content and then show it in a modal window

Community
  • 1
  • 1
IveGoogled
  • 121
  • 1
  • 1
  • 1
    If you had searched before posting you wouldn't post at all because there are countless questions like yours already answered here. – Jorge Guberte Oct 10 '11 at 16:52
  • even if I write a Greasemonkey script?? – IveGoogled Oct 10 '11 at 17:03
  • 1
    @iAsk: I recommend you try asking your question again with content more like, "I want to make a Greasemonkey script to show X from website Y whenever a user visits a site in category Z." Which will then immediately get responses like, "what have you tried so far?" and "where are you stuck?", so also include that information in your new question. As written, your question does not fully reflect the problem you are trying to solve and consequently is being marked as a duplicate. – Brian Oct 10 '11 at 20:17

4 Answers4

2

You can't. JavaScript must respect the same origin policy.

What you can do is ask your web server to contact the external site and extract the content.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

Due to the same origin policy restriction built into browsers cross domain scraping with only client side javascript is not possible. You could use a server side script to perform the task of fetching the contents of the remote site and parse it. Then using javascript you could query your server script to get the desired results.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

As you are using Greasemonkey, it is possible to make third-party requests. A jQuery-oriented tutorial is offered on this page. The short answer it to have Greasemonkey make the request on your behalf. Replace all your XMLHttpRequest objects with GM_xmlhttpRequest objects.

Brian
  • 25,523
  • 18
  • 82
  • 173
1

Realistically, I'd recommend using either PHP CURL or NodeJS to scrape remote content. Here's a NodeJS scraper you should check out: https://github.com/mape/node-scraper.

Timothy Perez
  • 20,154
  • 8
  • 51
  • 39