0

My question comes in two main parts. I am grateful for every helpful answer. I am quite a newbie when it comes to programming. Hence, I am missing the 'big picture'. To make research on Amazon easier, it would be helpful to pull information from the product detail pages into the gallery view page (the page shown after a search query is being made). In your opinion, what would be the best way to do this (first part)?

The way I decided to try is using Greasemonkey in combination with XmlHttpRequest, since I know JavaScript and I do research in the browser (Firefox 46), anyway. If there are way better methods, please tell me. I already pulled data from the source code, but I am really stuck when it comes to pulling data from other pages (within the same domain).

The first part of the code pulls the link to the detail page, but to keep this as short as possible, I omitted that. Here is what I have so far:

//This is an example-URL
var link = https://www.amazon.de/Emsa-513359-Isolierbecher-genie%C3%9Fen-Verschluss/dp/B008TLGFVU

function GetData() {
var xhr;  
xhr = new XMLHttpRequest(); 
}

//Handle Response from Server;
xhr.onreadystatechange = function () {
if (xhr.readyState < 4) {
    //Specify something }
    else {
    if (xhr.readyState === 4) {
    if (xhr.status == 200 && xhr.status < 300) {
    //This is the string / part of the product detail page, that I am interested in 
    document.getElementsByClassName('date-first-available')[0].getElementsByClassName('value')[0].innerHTML = xhr.responseText;

    //This grabs the title in the gallery view page and replaces it with the pulled informaton (string)
    var title = window.document.getElementsByClassName('s-result-item celwidget')[0].getElementsByTagName('h2')[0];
    title.innerHTML = <span style='font-weight:bold" + "'>" + xhr.responseText + "</span>"; 
    }}
}}

//Specify action, location and Send to the server   
xhr.open('GET', link, true);
xhr.send(); 

I know, that product title part is messy but I will change this soon. I also know, that "Why isn't this working?" questions are annoying, but I could really use some hints. Although it looks like XMLHttpRequest could be a working strategy here, I am not sure. Can I even specify the target element on the target page like that?

Thank you so much in advance!

Christian
  • 19
  • 4

0 Answers0