Optimal Way To Extract A Url From Web Page Loaded Via Xmlhttprequest?
Problem Overview I have a dynamically produced web page, X, which consists of search results linking to web pages, Y1, Y2, Y3 etc. Y1 contains a resource URL R1, Y2 contains resou
Solution 1:
You don't want to use regex to extract the URL. I suggest using jQuery to perform the AJAX request, and then use jQuery to parse and filter out the URLs from the HTML that is returned from the server.
jQuery.ajax({
url: "http://my.url.here",
dataType: "html";
...
success: function(data) {
jQuery("a", data).each(function() {
var $link = jQuery(this);
...
...
});
}
...
});
If jQuery is not an option, you can do something like this when you get your response back:
var html = XHR.responseText;
var div = document.createElement("div");
div.innerHTML = html;
//you can now search for nodes inside your div.//The following gives you all the anchor tags
div.getElementsByTagName('a');
...
Post a Comment for "Optimal Way To Extract A Url From Web Page Loaded Via Xmlhttprequest?"