Greasy Fork is available in English.

Dyskusje » Tworzenie skryptów

Scraping Problems

§
Napisano: 25-07-2020
Edytowano: 25-07-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
§
Napisano: 25-07-2020

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

§
Napisano: 25-07-2020

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

wOxxOmMod
§
Napisano: 25-07-2020

You've lost l at the end.

§
Napisano: 25-07-2020

what exactly do you mean by that?

wOxxOmMod
§
Napisano: 25-07-2020

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

§
Napisano: 26-07-2020

wOxxOm is referring to line 36 in your latest screenshot.

§
Napisano: 27-07-2020

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

§
Napisano: 27-07-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
}

})();

Odpowiedz

Zaloguj się, by odpowiedzieć.