Get content from an external website? [duplicate]
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
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.
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.
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.
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.
精彩评论