|
Rank: Advanced Member Groups: Member
Joined: 5/10/2021 Posts: 43
|
hello, good afternoon, I am working with a GET request with the XMLhttprequest request with the GET method and I have a problem working with the response. so far I manage to get the responses successfully from the server and I get the HTML in text format with the type ".responseText" and when I try to convert it to a document, html, Json or XML format I don't get anything. try to create an external function and load the elements in the second webview so as not to trip over the execution of the first wbview and it does not give me an error either and finally try to open a new window and load this window with the html in text format with a document.write and then close it and execute the function to extract the price of an article and the webview does not execute anything, it does not give me an error but I don't get any data. on the other hand I have all the perfect html with the responseText inside a variable but I cannot obtain and manipulate any data because it is a text and I cannot apply a function to extract the prices of the articles, I am going to place a copy of the code to see what this is missing
Code: Visual Basic.NET
Public Sub Conexion_HTMLhttpResquest()
Dim JS_CODE As String
Dim Navegador2 As Class1 = New Class1
Precarga_WEB("https://www.heb.com.mx/super/frutas-y-verduras")
JS_CODE = "(function ()
{
function extraer_url(nro) {
try {
return document.querySelectorAll('li.product-item div.product-item-info a')[nro].href;
} catch(err) {};
};
function extraer_precio(nro) {
return newdocument.document.querySelectorAll('span.price')[nro].innerText;
};
var url = extraer_url(0);
var newdocument = null;
for (i=0;i<1;i++) {
url = extraer_url(i);
var req = new XMLHttpRequest();
req.open('GET', url, true);
req.responseType = 'document';
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200) {
newdocument = req.response;
window.external.precio(extraer_precio(i));
} else {
alert('err in pag1');
};
};
};
req.send(null);
};
return url;
})();"
Dim Test_url As String = Me.WebControl1.WebView.EvalScript(JS_CODE)
at least I need help to learn how to manipulate the response of XMLhttprequest, since it is complicated to manipulate the html response in text, I am already grateful for any information you can give me, since I have support valid until June 11 , after this I will need to update my license with you, but I need to finish this project to see when I can update to the new version, thanks in advance.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
This is not how XMLHttpRequest typically is used. In a typical XMLHttpRequest scenario, you have control over both the client and server side or at least the server side is clearly documented. In another word, the server side and the client side must work together so that the server always returns the data format that your the can understand. The most common format is JSON since JavaScript has built-in JSON parser. So basically your client side script makes XMLHttpRequest call and the server returns JSON data, then your client side script read the JSON data and that's it. If the server side does not work with you, then the whole XMLHttpRequest mechanism would become useless to you because you would be writing client side code depending on some server side code that can change any time and your code would break and become useless anytime they make a change.
As to parsing returned HTML, a simple Google search on "JavaScript parsing HTML" should give you plenty of answers.
Overall your question really does not have anything to do with our product at all even though it's a question you run into while using our product. Our official support policy does NOT cover such questions. This is like you ask the person who sold you a car about where to find a gas station. You should not rely on us for such questions in the future.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 5/10/2021 Posts: 43
|
Hello, good morning, then, in a few words, if the server does not give me a response in JSON and it gives me an HTML response, then it depends on what the server responds to me, because I have tried other cases with a page and the result returned is null or empty,
On the other hand, correct me if I'm wrong, the returned format of the "response" is not text but what the response server gives me?
I'm going to investigate what you're suggesting about documenting information about the javascript html parser to see if I can get more information, I'll ask you if I have any other questions, but I think I can move forward with this.
thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Prequena84 wrote:Hello, good morning, then, in a few words, if the server does not give me a response in JSON and it gives me an HTML response, then it depends on what the server responds to me, because I have tried other cases with a page and the result returned is null or empty,
On the other hand, correct me if I'm wrong, the returned format of the "response" is not text but what the response server gives me? This is a question for your server. For example, if you call Microsoft Azure API, they will tell you exactly what format their response is and then you write code according to that format. You should never write code depending on server that does not have a clear "contract" with you about what format their response is because your code will become useless when they make changes.
|
|
Rank: Advanced Member Groups: Member
Joined: 5/10/2021 Posts: 43
|
I have no problem with the changes because I have an agreement with my clients when the html changes, I update the web scrapers from time to time and the product has gone well for us, however I am studying how to manipulate the html returned on this page for that is the response from the server of this web store, and we are in the stage of integrating XMLhttpResqueq as a communicator, so I do not worry about the changes, only that there must be a way to manipulate that returned htm in some way, And that's what I'm investigating, and well, if I learn anything else, I'll let you know.
|
|