Grab contents of a webpage in GWT
Let's say that I have a link to a webpage开发者_JAVA技巧 that contains some text. What's the easiest way to grab this text to process?
Thanks.
Long story short, I don't think it's possible to make a request from the client js to grab the text from a url with a different domain.
It is possible to make requests to load json. This link describes how.
Basically, the steps are:
- Embed a tag in the GWT page
- after GWT page is initialized, update the script tag's src to load remote url
- remote url returns some json data padded inside a callback javascript function such as: callback({blah:foo})
So, you're only option may be writing a method on the server side that loads the url, gets the text. You could then call this method from gwt client using normal rpc technique.
Assuming same origin: use the "RequestBuilder" class.
If you are trying to grab a webpage from a different origin, then it obviously won't work.
精彩评论