Discussions » Development

Scraping Problems

§
Posted: 25.7.2020
Edited: 25.7.2020

Scraping Problems

Hello. Unfortunately I have a problem on one page. I can't get the data URL. The screenshot is attached. Many thanks for the help

woxxomMod
§
Posted: 25.7.2020

e.querySelector('div[data-url]').dataset.url

§
Posted: 25.7.2020

Thank you very much. Unfortunately, it doesn't work. Is it due to the reference above ??

woxxomMod
§
Posted: 25.7.2020

You've lost l at the end.

§
Posted: 25.7.2020

what exactly do you mean by that?

woxxomMod
§
Posted: 25.7.2020

ur on your screenshot at the end of the copied line should be url.

§
Posted: 26.7.2020

wOxxOm is referring to line 36 in your latest screenshot.

§
Posted: 27.7.2020

great. unfortunately it doesn't work yet. There is a small error in the code that I cannot find :(

§
Posted: 27.7.2020

// ==UserScript== // @name aponeo // @namespace http://tampermonkey.net/ // @version 0.1 // @description aponeo // @author Nexuz89 // @match https://www.aponeo.de/* // @grant none // ==/UserScript==

(function() { 'use strict';

window.setTimeout(installButton, 1000)

function installButton() {
    const elem = document.createElement('button')
    elem.innerText = 'Copy'
    elem.style = 'z-index: 100000; position:fixed; top:0; left:0';
    document.body.appendChild(elem);
    elem.addEventListener('click', _ => exportCsv())
}

function exportCsv() {
    let products = Array.prototype.map.call(document.querySelectorAll("div['apn-product-list-item'"), e => e)
    let csv = products.map(productObject).map(p => '"' + p.title + '",' + p.price + ',"' + p.url + '"').join('\n')
    console.log(csv)
    navigator.clipboard.writeText(csv)
        .then(_ => window.alert('In Zwischenablage kopiert'),
              _ => window.alert('Fehler beim Kopieren in Zwischenablage'))
}

function productObject(e) {
    const result = {};

    result.url = e.querySelector('div[data-url]').dataset.url
    return result
}

})();

Post reply

Sign in to post a reply.